// testonce.cpp // // (C) Copyright 2005 Anthony Williams // // 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) #include "once_atomic.hpp" #include #include #include #include #include unsigned counter=0; void increment_counter() { ++counter; } void test_once() { boost::once_flag flag=BOOST_ONCE_INIT; counter=0; unsigned const loop_count=100000; for(unsigned i=0;i(thread_counter)); static boost::once_flag once2=BOOST_ONCE_INIT; boost::call_once(increment_counter,once2); InterlockedIncrement(static_cast(thread_counter)); static boost::once_flag once3=BOOST_ONCE_INIT; boost::call_once(increment_counter,once3); InterlockedIncrement(static_cast(thread_counter)); static boost::once_flag once4=BOOST_ONCE_INIT; boost::call_once(increment_counter,once4); InterlockedIncrement(static_cast(thread_counter)); static boost::once_flag once5=BOOST_ONCE_INIT; boost::call_once(increment_counter,once5); InterlockedIncrement(static_cast(thread_counter)); static boost::once_flag once6=BOOST_ONCE_INIT; boost::call_once(increment_counter,once6); InterlockedIncrement(static_cast(thread_counter)); static boost::once_flag once7=BOOST_ONCE_INIT; boost::call_once(increment_counter,once7); InterlockedIncrement(static_cast(thread_counter)); static boost::once_flag once8=BOOST_ONCE_INIT; boost::call_once(increment_counter,once8); InterlockedIncrement(static_cast(thread_counter)); static boost::once_flag once9=BOOST_ONCE_INIT; boost::call_once(increment_counter,once9); InterlockedIncrement(static_cast(thread_counter)); return 0; } void test_once_multiple_threads() { unsigned const number_of_threads=20; counter=0; HANDLE handles[number_of_threads]={0}; unsigned thread_count=0; for(unsigned i=0;i