test_7720.cpp 936 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright (C) 2013 Vicente Botet
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ////////////////////////////////////////////
  6. //#define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN
  7. #include <boost/thread/thread_only.hpp>
  8. #include <boost/thread/shared_mutex.hpp>
  9. using namespace boost;
  10. shared_mutex mtx;
  11. const int max_count = 100;
  12. void f()
  13. {
  14. int count =max_count;
  15. while (count--)
  16. {
  17. upgrade_lock<shared_mutex> lock(mtx);
  18. }
  19. }
  20. void g()
  21. {
  22. int count =max_count;
  23. while (count--)
  24. {
  25. shared_lock<shared_mutex> lock(mtx);
  26. }
  27. }
  28. void h()
  29. {
  30. int count =max_count;
  31. while (count--)
  32. {
  33. unique_lock<shared_mutex> lock(mtx);
  34. }
  35. }
  36. int main()
  37. {
  38. thread t0(f);
  39. thread t1(g);
  40. thread t2(h);
  41. t0.join();
  42. t1.join();
  43. t2.join();
  44. return 0;
  45. }