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 | //////////////////////////////////////////// |
7 | |
8 | //#define BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN |
9 | #include <boost/thread/thread_only.hpp> |
10 | #include <boost/thread/shared_mutex.hpp> |
11 | using namespace boost; |
12 | |
13 | shared_mutex mtx; |
14 | |
15 | const int max_count = 100; |
16 | void f() |
17 | { |
18 | int count =max_count; |
19 | while (count--) |
20 | { |
21 | upgrade_lock<shared_mutex> lock(mtx); |
22 | } |
23 | } |
24 | |
25 | void g() |
26 | { |
27 | int count =max_count; |
28 | while (count--) |
29 | { |
30 | shared_lock<shared_mutex> lock(mtx); |
31 | } |
32 | } |
33 | |
34 | void h() |
35 | { |
36 | int count =max_count; |
37 | while (count--) |
38 | { |
39 | unique_lock<shared_mutex> lock(mtx); |
40 | } |
41 | } |
42 | |
43 | int main() |
44 | { |
45 | thread t0(f); |
46 | thread t1(g); |
47 | thread t2(h); |
48 | |
49 | t0.join(); |
50 | t1.join(); |
51 | t2.join(); |
52 | |
53 | return 0; |
54 | } |
55 | |
56 | |
57 |