1 // (C) Copyright Gennadiy Rozental 2008-2015.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // See http://www.boost.org/libs/test for the library home page.
10 // Version : $Revision$
12 // Description : tests Unit Test Framework usability in MT environment with
13 // Boost.Test calls externally synchronized
14 // ***************************************************************************
16 #define BOOST_TEST_MODULE sync_access_test
17 #include <boost/test/unit_test.hpp>
19 #include <boost/thread.hpp>
20 #include <boost/thread/barrier.hpp>
21 #include <boost/bind/bind.hpp>
22 #include <boost/ref.hpp>
24 using namespace boost
;
25 namespace ut
= boost::unit_test
;
27 static boost::mutex m
;
29 /// thread execution function
30 static void thread_function(boost::barrier
& b
)
32 b
.wait(); /// wait until memory barrier allows the execution
33 boost::mutex::scoped_lock
lock(m
); /// lock mutex
34 BOOST_TEST(1 ==0 ); /// produce the fault
37 #if BOOST_PP_VARIADICS
38 /// test function which creates threads
39 BOOST_AUTO_TEST_CASE( test_multiple_assertion_faults
, * ut::expected_failures(100))
42 * ut::expected_failures(100)
44 BOOST_AUTO_TEST_CASE( test_multiple_assertion_faults
)
47 boost::thread_group tg
; // thread group to manage all threads
48 boost::barrier
b(100); // memory barrier, which should block all threads
49 // until all 100 threads were created
51 for(size_t i
=0; i
<100; ++i
)
52 tg
.create_thread(boost::bind(thread_function
, ref(b
))); /// create a thread and pass it the barrier