2 (C) Copyright 2007-8 Anthony Williams.
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at
5 http://www.boost.org/LICENSE_1_0.txt).
8 [section:shared_mutex Class `shared_mutex` -- C++14]
10 #include <boost/thread/shared_mutex.hpp>
15 shared_mutex(shared_mutex const&) = delete;
16 shared_mutex& operator=(shared_mutex const&) = delete;
22 bool try_lock_shared();
23 template <class Rep, class Period>
24 bool try_lock_shared_for(const chrono::duration<Rep, Period>& rel_time);
25 template <class Clock, class Duration>
26 bool try_lock_shared_until(const chrono::time_point<Clock, Duration>& abs_time);
31 template <class Rep, class Period>
32 bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
33 template <class Clock, class Duration>
34 bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
37 #if defined BOOST_THREAD_PROVIDES_DEPRECATED_FEATURES_SINCE_V3_0_0
38 // use upgrade_mutex instead.
39 void lock_upgrade(); // EXTENSION
40 void unlock_upgrade(); // EXTENSION
42 void unlock_upgrade_and_lock(); // EXTENSION
43 void unlock_and_lock_upgrade(); // EXTENSION
44 void unlock_and_lock_shared(); // EXTENSION
45 void unlock_upgrade_and_lock_shared(); // EXTENSION
48 #if defined BOOST_THREAD_USES_DATETIME
49 bool timed_lock_shared(system_time const& timeout); // DEPRECATED
50 bool timed_lock(system_time const& timeout); // DEPRECATED
55 The class `boost::shared_mutex` provides an implementation of a multiple-reader / single-writer mutex. It implements the
56 __shared_lockable_concept__.
58 Multiple concurrent calls to __lock_ref__, __try_lock_ref__, `__try_lock_for()`, `__try_lock_until()`, __timed_lock_ref__, __lock_shared_ref__,
59 `__try_lock_shared_for()`, `__try_lock_shared_until()`, __try_lock_shared_ref__ and __timed_lock_shared_ref__ are permitted.
61 Note the the lack of reader-writer priority policies in shared_mutex. This is due to an algorithm credited to Alexander Terekhov which lets the OS decide which thread is the next to get the lock without caring whether a unique lock or shared lock is being sought. This results in a complete lack of reader or writer starvation. It is simply fair.
65 [section:upgrade_mutex Class `upgrade_mutex` -- EXTENSION]
67 #include <boost/thread/shared_mutex.hpp>
72 upgrade_mutex(upgrade_mutex const&) = delete;
73 upgrade_mutex& operator=(upgrade_mutex const&) = delete;
79 bool try_lock_shared();
80 template <class Rep, class Period>
81 bool try_lock_shared_for(const chrono::duration<Rep, Period>& rel_time);
82 template <class Clock, class Duration>
83 bool try_lock_shared_until(const chrono::time_point<Clock, Duration>& abs_time);
88 template <class Rep, class Period>
89 bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
90 template <class Clock, class Duration>
91 bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
95 template <class Rep, class Period>
96 bool try_lock_upgrade_for(const chrono::duration<Rep, Period>& rel_time);
97 template <class Clock, class Duration>
98 bool try_lock_upgrade_until(const chrono::time_point<Clock, Duration>& abs_time);
99 void unlock_upgrade();
101 // Shared <-> Exclusive
103 #ifdef BOOST_THREAD_PROVIDES_SHARED_MUTEX_UPWARDS_CONVERSIONS
104 bool try_unlock_shared_and_lock();
105 template <class Rep, class Period>
106 bool try_unlock_shared_and_lock_for(const chrono::duration<Rep, Period>& rel_time);
107 template <class Clock, class Duration>
108 bool try_unlock_shared_and_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
110 void unlock_and_lock_shared();
112 // Shared <-> Upgrade
114 #ifdef BOOST_THREAD_PROVIDES_SHARED_MUTEX_UPWARDS_CONVERSIONS
115 bool try_unlock_shared_and_lock_upgrade();
116 template <class Rep, class Period>
117 bool try_unlock_shared_and_lock_upgrade_for(const chrono::duration<Rep, Period>& rel_time);
118 template <class Clock, class Duration>
119 bool try_unlock_shared_and_lock_upgrade_until(const chrono::time_point<Clock, Duration>& abs_time);
121 void unlock_upgrade_and_lock_shared();
123 // Upgrade <-> Exclusive
125 void unlock_upgrade_and_lock();
126 #if defined(BOOST_THREAD_PLATFORM_PTHREAD)
127 || defined(BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN)
128 bool try_unlock_upgrade_and_lock();
129 template <class Rep, class Period>
130 bool try_unlock_upgrade_and_lock_for(const chrono::duration<Rep, Period>& rel_time);
131 template <class Clock, class Duration>
132 bool try_unlock_upgrade_and_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
134 void unlock_and_lock_upgrade();
137 The class `boost::upgrade_mutex` provides an implementation of a multiple-reader / single-writer mutex. It implements the
138 __upgrade_lockable_concept__.
140 Multiple concurrent calls to __lock_ref__, __try_lock_ref__, `__try_lock_for()`, `__try_lock_until()`, __timed_lock_ref__, __lock_shared_ref__,
141 `__try_lock_shared_for()`, `__try_lock_shared_until()`, __try_lock_shared_ref__ and __timed_lock_shared_ref__ are permitted.
146 [section:null_mutex Class `null_mutex` -- EXTENSION]
148 #include <boost/thread/null_mutex.hpp>
153 null_mutex(null_mutex const&) = delete;
154 null_mutex& operator=(null_mutex const&) = delete;
160 bool try_lock_shared();
161 #ifdef BOOST_THREAD_USES_CHRONO
162 template <class Rep, class Period>
163 bool try_lock_shared_for(const chrono::duration<Rep, Period>& rel_time);
164 template <class Clock, class Duration>
165 bool try_lock_shared_until(const chrono::time_point<Clock, Duration>& abs_time);
167 void unlock_shared();
171 #ifdef BOOST_THREAD_USES_CHRONO
172 template <class Rep, class Period>
173 bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
174 template <class Clock, class Duration>
175 bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
180 #ifdef BOOST_THREAD_USES_CHRONO
181 template <class Rep, class Period>
182 bool try_lock_upgrade_for(const chrono::duration<Rep, Period>& rel_time);
183 template <class Clock, class Duration>
184 bool try_lock_upgrade_until(const chrono::time_point<Clock, Duration>& abs_time);
186 void unlock_upgrade();
188 // Shared <-> Exclusive
190 bool try_unlock_shared_and_lock();
191 #ifdef BOOST_THREAD_USES_CHRONO
192 template <class Rep, class Period>
193 bool try_unlock_shared_and_lock_for(const chrono::duration<Rep, Period>& rel_time);
194 template <class Clock, class Duration>
195 bool try_unlock_shared_and_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
197 void unlock_and_lock_shared();
199 // Shared <-> Upgrade
201 bool try_unlock_shared_and_lock_upgrade();
202 #ifdef BOOST_THREAD_USES_CHRONO
203 template <class Rep, class Period>
204 bool try_unlock_shared_and_lock_upgrade_for(const chrono::duration<Rep, Period>& rel_time);
205 template <class Clock, class Duration>
206 bool try_unlock_shared_and_lock_upgrade_until(const chrono::time_point<Clock, Duration>& abs_time);
208 void unlock_upgrade_and_lock_shared();
210 // Upgrade <-> Exclusive
212 void unlock_upgrade_and_lock();
213 bool try_unlock_upgrade_and_lock();
214 #ifdef BOOST_THREAD_USES_CHRONO
215 template <class Rep, class Period>
216 bool try_unlock_upgrade_and_lock_for(const chrono::duration<Rep, Period>& rel_time);
217 template <class Clock, class Duration>
218 bool try_unlock_upgrade_and_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
220 void unlock_and_lock_upgrade();
223 The class `boost::null_mutex` provides a no-op implementation of a multiple-reader / single-writer mutex. It is a model of the
224 __UpgradeLockable concept.