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

source code of boost/libs/thread/test/test_6170.cpp