test_6170.cpp 771 B

12345678910111213141516171819202122232425262728293031
  1. // Copyright (C) 2010 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. #include <boost/thread/shared_mutex.hpp>
  6. #include <boost/thread/locks.hpp>
  7. // Including this will cause ambiguous errors in boost::move
  8. #include <boost/unordered_map.hpp>
  9. using namespace boost;
  10. typedef upgrade_lock<shared_mutex> auto_upgrade_lock;
  11. typedef upgrade_to_unique_lock<shared_mutex> auto_upgrade_unique_lock;
  12. void testUpgrade(void)
  13. {
  14. shared_mutex mtx;
  15. auto_upgrade_lock lock(mtx);
  16. // Do some read-only stuff
  17. auto_upgrade_unique_lock writeLock(lock);
  18. // Do some write-only stuff with the upgraded lock
  19. }
  20. int main()
  21. {
  22. testUpgrade();
  23. return 0;
  24. }