/Src/Dependencies/Boost/libs/test/test/sync_access_test.cpp

http://hadesmem.googlecode.com/ · C++ · 38 lines · 24 code · 10 blank · 4 comment · 1 complexity · 2a5689ae6444f69bc262f9dd90396f32 MD5 · raw file

  1. #define BOOST_TEST_MODULE sync_access_test
  2. #include <boost/test/unit_test.hpp>
  3. #include <boost/thread.hpp>
  4. #include <boost/thread/barrier.hpp>
  5. #include <boost/bind.hpp>
  6. #include <boost/ref.hpp>
  7. using namespace boost;
  8. namespace ut = boost::unit_test;
  9. static boost::mutex m;
  10. /// thread execution function
  11. static void thread_function(boost::barrier& b)
  12. {
  13. b.wait(); /// wait until memory barrier allows the execution
  14. boost::mutex::scoped_lock lock(m); /// lock mutex
  15. BOOST_CHECK_EQUAL(1,0); /// produce the fault
  16. }
  17. BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES( test_multiple_assertion_faults, 100 )
  18. /// test function which creates threads
  19. BOOST_AUTO_TEST_CASE( test_multiple_assertion_faults )
  20. {
  21. boost::thread_group tg; // thread group to manage all threads
  22. boost::barrier b(100); // memory barrier, which should block all threads
  23. // until all 100 threads were created
  24. for(size_t i=0; i<100; ++i)
  25. tg.create_thread(boost::bind(thread_function, ref(b))); /// create a thread and pass it the barrier
  26. tg.join_all();
  27. }
  28. // EOF