#include #include #include #include #include using namespace boost; namespace ut = boost::unit_test; static boost::mutex m; /// class used to produce an MT thread struct thread_safety_test { /// thread execution function static void thread_function(boost::barrier& b) { b.wait(); /// wait until memory barrier allows the execution boost::mutex::scoped_lock lock(m); /// lock mutex BOOST_CHECK_EQUAL(1,0); /// produce the fault } /// test function which creates threads void test_multiple_assertion_faults() { boost::thread_group tg; // thread group to manage all threads boost::barrier b(100); // memory barrier, which should block all threads // until all 100 threads were created for(size_t i=0; i<100; ++i) tg.create_thread(boost::bind(thread_function, ref(b))); /// create a thread and pass it the barrier tg.join_all; } }; ut::test_suite* init_unit_test_suite(int /*argc*/, char* /*argv*/[]) { ut::test_suite* suite = BOOST_TEST_SUITE("multi-threaded Boost.Test test"); shared_ptr thread_test(new thread_safety_test); suite->add( BOOST_CLASS_TEST_CASE(&thread_safety_test::test_multiple_assertion_faults, thread_test) ); return suite; }