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 | |
12 | using namespace boost; |
13 | |
14 | typedef upgrade_lock<shared_mutex> auto_upgrade_lock; |
15 | typedef upgrade_to_unique_lock<shared_mutex> auto_upgrade_unique_lock; |
16 | |
17 | void 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 | |
27 | int main() |
28 | { |
29 | testUpgrade(); |
30 | return 0; |
31 | } |
32 |