2
0
mirror of https://github.com/boostorg/sync.git synced 2026-01-19 04:42:12 +00:00
Files
sync/test/run/at_thread_exit.cpp
Andrey Semashev ffd2a86d5f Ported tests to lightweight_test.hpp.
This will allow to work around compilation warnings and errors on
MinGW coming from Boost.Test.
2019-01-03 21:22:44 +03:00

48 lines
942 B
C++

/*
* Copyright Andrey Semashev 2013.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
/*!
* \file at_thread_exit.cpp
*
* \brief This test checks that \c at_thread_exit works
*/
#include <boost/core/lightweight_test.hpp>
#include <boost/thread/thread.hpp>
#include <boost/sync/thread_specific/at_thread_exit.hpp>
unsigned int called = 0;
struct my_at_thread_exit
{
typedef void result_type;
explicit my_at_thread_exit(unsigned int& n) : m_called(&n) {}
void operator() () const
{
++(*m_called);
}
private:
unsigned int* m_called;
};
void my_thread_routine()
{
boost::sync::at_thread_exit(my_at_thread_exit(called));
}
int main()
{
boost::thread t(&my_thread_routine);
t.join();
BOOST_TEST_EQ(called, 1u);
return boost::report_errors();
}