2
0
mirror of https://github.com/boostorg/thread.git synced 2026-01-23 18:12:12 +00:00
Files
thread/test/test_call_once.cpp
William E. Kempf 4808ccb316 Refactoring tests
[SVN r13936]
2002-05-15 22:01:36 +00:00

31 lines
549 B
C++

#include <boost/thread/thread.hpp>
#include <boost/thread/once.hpp>
#include <boost/test/test_tools.hpp>
namespace {
int once_value = 0;
boost::once_flag once = BOOST_ONCE_INIT;
void init_once_value()
{
once_value++;
}
void test_once_thread()
{
boost::call_once(&init_once_value, once);
}
} // namespace
void test_call_once()
{
const int NUMTHREADS=5;
boost::thread_group threads;
for (int i=0; i<NUMTHREADS; ++i)
threads.create_thread(&test_once_thread);
threads.join_all();
BOOST_TEST(once_value == 1);
}