// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
+#define BOOST_THREAD_VERSION 2
+#define BOOST_THREAD_PROVIDES_INTERRUPTIONS
+
#include <boost/test/unit_test.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/once.hpp>
+#define LOG \
+ if (false) {} else std::cout << std::endl << __FILE__ << "[" << __LINE__ << "]"
+
boost::once_flag flag=BOOST_ONCE_INIT;
int var_to_init=0;
boost::mutex m;
void initialize_variable()
{
// ensure that if multiple threads get in here, they are serialized, so we can see the effect
- boost::mutex::scoped_lock lock(m);
+ boost::unique_lock<boost::mutex> lock(m);
++var_to_init;
}
break;
}
}
- boost::mutex::scoped_lock lock(m);
+ boost::unique_lock<boost::mutex> lock(m);
BOOST_CHECK_EQUAL(my_once_value, 1);
}
void test_call_once()
{
+ LOG;
+
unsigned const num_threads=20;
boost::thread_group group;
explicit increment_value(int* value_):
value(value_)
{}
-
+
void operator()() const
{
- boost::mutex::scoped_lock lock(m);
+ boost::unique_lock<boost::mutex> lock(m);
++(*value);
}
};
break;
}
}
- boost::mutex::scoped_lock lock(m);
+ boost::unique_lock<boost::mutex> lock(m);
BOOST_CHECK_EQUAL(my_once_value, 1);
}
void test_call_once_arbitrary_functor()
{
+ LOG;
+
unsigned const num_threads=20;
boost::thread_group group;
{};
static unsigned pass_counter;
-
+
void operator()() const
{
- boost::mutex::scoped_lock lock(m);
+ boost::unique_lock<boost::mutex> lock(m);
++pass_counter;
if(pass_counter<3)
{
}
catch(throw_before_third_pass::my_exception)
{
- boost::mutex::scoped_lock lock(m);
+ boost::unique_lock<boost::mutex> lock(m);
++exception_counter;
}
}
void test_call_once_retried_on_exception()
{
+ LOG;
unsigned const num_threads=20;
boost::thread_group group;
return test;
}
+
+