1// <shared_mutex> -*- C++ -*-
3// Copyright (C) 2013-2024 Free Software Foundation, Inc.
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
25/** @file include/shared_mutex
26 * This is a Standard C++ Library header.
29#ifndef _GLIBCXX_SHARED_MUTEX
30#define _GLIBCXX_SHARED_MUTEX 1
32#pragma GCC system_header
34#include <bits/requires_hosted.h> // concurrency
36#if __cplusplus >= 201402L
38#include <bits/chrono.h>
39#include <bits/error_constants.h>
40#include <bits/functexcept.h>
41#include <bits/move.h> // move, __exchange
42#include <bits/std_mutex.h> // defer_lock_t
44#define __glibcxx_want_shared_mutex
45#define __glibcxx_want_shared_timed_mutex
46#include <bits/version.h>
48#if ! (_GLIBCXX_USE_PTHREAD_RWLOCK_T && _GTHREAD_USE_MUTEX_TIMEDLOCK)
49# include <condition_variable>
52namespace std _GLIBCXX_VISIBILITY(default)
54_GLIBCXX_BEGIN_NAMESPACE_VERSION
61#ifdef _GLIBCXX_HAS_GTHREADS
63#ifdef __cpp_lib_shared_mutex // C++ >= 17 && hosted && gthread
67 class shared_timed_mutex;
69 /// @cond undocumented
71#if _GLIBCXX_USE_PTHREAD_RWLOCK_T
73#define _GLIBCXX_GTHRW(name) \
74 __gthrw(pthread_ ## name); \
76 __glibcxx_ ## name (pthread_rwlock_t *__rwlock) \
78 if (__gthread_active_p ()) \
79 return __gthrw_(pthread_ ## name) (__rwlock); \
83 _GLIBCXX_GTHRW(rwlock_rdlock)
84 _GLIBCXX_GTHRW(rwlock_tryrdlock)
85 _GLIBCXX_GTHRW(rwlock_wrlock)
86 _GLIBCXX_GTHRW(rwlock_trywrlock)
87 _GLIBCXX_GTHRW(rwlock_unlock)
88# ifndef PTHREAD_RWLOCK_INITIALIZER
89 _GLIBCXX_GTHRW(rwlock_destroy)
90 __gthrw(pthread_rwlock_init);
92 __glibcxx_rwlock_init (pthread_rwlock_t *__rwlock)
94 if (__gthread_active_p ())
95 return __gthrw_(pthread_rwlock_init) (__rwlock, NULL);
100# if _GTHREAD_USE_MUTEX_TIMEDLOCK
101 __gthrw(pthread_rwlock_timedrdlock);
103 __glibcxx_rwlock_timedrdlock (pthread_rwlock_t *__rwlock,
104 const timespec *__ts)
106 if (__gthread_active_p ())
107 return __gthrw_(pthread_rwlock_timedrdlock) (__rwlock, __ts);
111 __gthrw(pthread_rwlock_timedwrlock);
113 __glibcxx_rwlock_timedwrlock (pthread_rwlock_t *__rwlock,
114 const timespec *__ts)
116 if (__gthread_active_p ())
117 return __gthrw_(pthread_rwlock_timedwrlock) (__rwlock, __ts);
124 __glibcxx_rwlock_rdlock (pthread_rwlock_t *__rwlock)
125 { return pthread_rwlock_rdlock (__rwlock); }
127 __glibcxx_rwlock_tryrdlock (pthread_rwlock_t *__rwlock)
128 { return pthread_rwlock_tryrdlock (__rwlock); }
130 __glibcxx_rwlock_wrlock (pthread_rwlock_t *__rwlock)
131 { return pthread_rwlock_wrlock (__rwlock); }
133 __glibcxx_rwlock_trywrlock (pthread_rwlock_t *__rwlock)
134 { return pthread_rwlock_trywrlock (__rwlock); }
136 __glibcxx_rwlock_unlock (pthread_rwlock_t *__rwlock)
137 { return pthread_rwlock_unlock (__rwlock); }
139 __glibcxx_rwlock_destroy(pthread_rwlock_t *__rwlock)
140 { return pthread_rwlock_destroy (__rwlock); }
142 __glibcxx_rwlock_init(pthread_rwlock_t *__rwlock)
143 { return pthread_rwlock_init (__rwlock, NULL); }
144# if _GTHREAD_USE_MUTEX_TIMEDLOCK
146 __glibcxx_rwlock_timedrdlock (pthread_rwlock_t *__rwlock,
147 const timespec *__ts)
148 { return pthread_rwlock_timedrdlock (__rwlock, __ts); }
150 __glibcxx_rwlock_timedwrlock (pthread_rwlock_t *__rwlock,
151 const timespec *__ts)
152 { return pthread_rwlock_timedwrlock (__rwlock, __ts); }
156 /// A shared mutex type implemented using pthread_rwlock_t.
157 class __shared_mutex_pthread
159 friend class shared_timed_mutex;
161#ifdef PTHREAD_RWLOCK_INITIALIZER
162 pthread_rwlock_t _M_rwlock = PTHREAD_RWLOCK_INITIALIZER;
165 __shared_mutex_pthread() = default;
166 ~__shared_mutex_pthread() = default;
168 pthread_rwlock_t _M_rwlock;
171 __shared_mutex_pthread()
173 int __ret = __glibcxx_rwlock_init(&_M_rwlock);
176 else if (__ret == EAGAIN)
177 __throw_system_error(int(errc::resource_unavailable_try_again));
178 else if (__ret == EPERM)
179 __throw_system_error(int(errc::operation_not_permitted));
180 // Errors not handled: EBUSY, EINVAL
181 __glibcxx_assert(__ret == 0);
184 ~__shared_mutex_pthread()
186 int __ret __attribute((__unused__)) = __glibcxx_rwlock_destroy(&_M_rwlock);
187 // Errors not handled: EBUSY, EINVAL
188 __glibcxx_assert(__ret == 0);
192 __shared_mutex_pthread(const __shared_mutex_pthread&) = delete;
193 __shared_mutex_pthread& operator=(const __shared_mutex_pthread&) = delete;
198 int __ret = __glibcxx_rwlock_wrlock(&_M_rwlock);
199 if (__ret == EDEADLK)
200 __throw_system_error(int(errc::resource_deadlock_would_occur));
201 // Errors not handled: EINVAL
202 __glibcxx_assert(__ret == 0);
208 int __ret = __glibcxx_rwlock_trywrlock(&_M_rwlock);
209 if (__ret == EBUSY) return false;
210 // Errors not handled: EINVAL
211 __glibcxx_assert(__ret == 0);
218 int __ret __attribute((__unused__)) = __glibcxx_rwlock_unlock(&_M_rwlock);
219 // Errors not handled: EPERM, EBUSY, EINVAL
220 __glibcxx_assert(__ret == 0);
229 // We retry if we exceeded the maximum number of read locks supported by
230 // the POSIX implementation; this can result in busy-waiting, but this
231 // is okay based on the current specification of forward progress
232 // guarantees by the standard.
234 __ret = __glibcxx_rwlock_rdlock(&_M_rwlock);
235 while (__ret == EAGAIN);
236 if (__ret == EDEADLK)
237 __throw_system_error(int(errc::resource_deadlock_would_occur));
238 // Errors not handled: EINVAL
239 __glibcxx_assert(__ret == 0);
245 int __ret = __glibcxx_rwlock_tryrdlock(&_M_rwlock);
246 // If the maximum number of read locks has been exceeded, we just fail
247 // to acquire the lock. Unlike for lock(), we are not allowed to throw
249 if (__ret == EBUSY || __ret == EAGAIN) return false;
250 // Errors not handled: EINVAL
251 __glibcxx_assert(__ret == 0);
261 void* native_handle() { return &_M_rwlock; }
265#if ! (_GLIBCXX_USE_PTHREAD_RWLOCK_T && _GTHREAD_USE_MUTEX_TIMEDLOCK)
266 /// A shared mutex type implemented using std::condition_variable.
267 class __shared_mutex_cv
269 friend class shared_timed_mutex;
271 // Based on Howard Hinnant's reference implementation from N2406.
273 // The high bit of _M_state is the write-entered flag which is set to
274 // indicate a writer has taken the lock or is queuing to take the lock.
275 // The remaining bits are the count of reader locks.
277 // To take a reader lock, block on gate1 while the write-entered flag is
278 // set or the maximum number of reader locks is held, then increment the
279 // reader lock count.
280 // To release, decrement the count, then if the write-entered flag is set
281 // and the count is zero then signal gate2 to wake a queued writer,
282 // otherwise if the maximum number of reader locks was held signal gate1
285 // To take a writer lock, block on gate1 while the write-entered flag is
286 // set, then set the write-entered flag to start queueing, then block on
287 // gate2 while the number of reader locks is non-zero.
288 // To release, unset the write-entered flag and signal gate1 to wake all
289 // blocked readers and writers.
291 // This means that when no reader locks are held readers and writers get
292 // equal priority. When one or more reader locks is held a writer gets
293 // priority and no more reader locks can be taken while the writer is
296 // Only locked when accessing _M_state or waiting on condition variables.
298 // Used to block while write-entered is set or reader count at maximum.
299 condition_variable _M_gate1;
300 // Used to block queued writers while reader count is non-zero.
301 condition_variable _M_gate2;
302 // The write-entered flag and reader count.
305 static constexpr unsigned _S_write_entered
306 = 1U << (sizeof(unsigned)*__CHAR_BIT__ - 1);
307 static constexpr unsigned _S_max_readers = ~_S_write_entered;
309 // Test whether the write-entered flag is set. _M_mut must be locked.
310 bool _M_write_entered() const { return _M_state & _S_write_entered; }
312 // The number of reader locks currently held. _M_mut must be locked.
313 unsigned _M_readers() const { return _M_state & _S_max_readers; }
316 __shared_mutex_cv() : _M_state(0) {}
320 __glibcxx_assert( _M_state == 0 );
323 __shared_mutex_cv(const __shared_mutex_cv&) = delete;
324 __shared_mutex_cv& operator=(const __shared_mutex_cv&) = delete;
326 // Exclusive ownership
331 unique_lock<mutex> __lk(_M_mut);
332 // Wait until we can set the write-entered flag.
333 _M_gate1.wait(__lk, [=]{ return !_M_write_entered(); });
334 _M_state |= _S_write_entered;
335 // Then wait until there are no more readers.
336 _M_gate2.wait(__lk, [=]{ return _M_readers() == 0; });
342 unique_lock<mutex> __lk(_M_mut, try_to_lock);
343 if (__lk.owns_lock() && _M_state == 0)
345 _M_state = _S_write_entered;
354 lock_guard<mutex> __lk(_M_mut);
355 __glibcxx_assert( _M_write_entered() );
357 // call notify_all() while mutex is held so that another thread can't
358 // lock and unlock the mutex then destroy *this before we make the call.
359 _M_gate1.notify_all();
367 unique_lock<mutex> __lk(_M_mut);
368 _M_gate1.wait(__lk, [=]{ return _M_state < _S_max_readers; });
375 unique_lock<mutex> __lk(_M_mut, try_to_lock);
376 if (!__lk.owns_lock())
378 if (_M_state < _S_max_readers)
389 lock_guard<mutex> __lk(_M_mut);
390 __glibcxx_assert( _M_readers() > 0 );
391 auto __prev = _M_state--;
392 if (_M_write_entered())
394 // Wake the queued writer if there are no more readers.
395 if (_M_readers() == 0)
396 _M_gate2.notify_one();
397 // No need to notify gate1 because we give priority to the queued
398 // writer, and that writer will eventually notify gate1 after it
399 // clears the write-entered flag.
403 // Wake any thread that was blocked on reader overflow.
404 if (__prev == _S_max_readers)
405 _M_gate1.notify_one();
412#ifdef __cpp_lib_shared_mutex
413 /// The standard shared mutex type.
417 shared_mutex() = default;
418 ~shared_mutex() = default;
420 shared_mutex(const shared_mutex&) = delete;
421 shared_mutex& operator=(const shared_mutex&) = delete;
423 // Exclusive ownership
425 void lock() { _M_impl.lock(); }
426 [[nodiscard]] bool try_lock() { return _M_impl.try_lock(); }
427 void unlock() { _M_impl.unlock(); }
431 void lock_shared() { _M_impl.lock_shared(); }
432 [[nodiscard]] bool try_lock_shared() { return _M_impl.try_lock_shared(); }
433 void unlock_shared() { _M_impl.unlock_shared(); }
435#if _GLIBCXX_USE_PTHREAD_RWLOCK_T
436 typedef void* native_handle_type;
437 native_handle_type native_handle() { return _M_impl.native_handle(); }
440 __shared_mutex_pthread _M_impl;
443 __shared_mutex_cv _M_impl;
446#endif // __cpp_lib_shared_mutex
448 /// @cond undocumented
449#if _GLIBCXX_USE_PTHREAD_RWLOCK_T && _GTHREAD_USE_MUTEX_TIMEDLOCK
450 using __shared_timed_mutex_base = __shared_mutex_pthread;
452 using __shared_timed_mutex_base = __shared_mutex_cv;
456 /// The standard shared timed mutex type.
457 class shared_timed_mutex
458 : private __shared_timed_mutex_base
460 using _Base = __shared_timed_mutex_base;
462 // Must use the same clock as condition_variable for __shared_mutex_cv.
463#ifdef _GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK
464 using __clock_t = chrono::steady_clock;
466 using __clock_t = chrono::system_clock;
470 shared_timed_mutex() = default;
471 ~shared_timed_mutex() = default;
473 shared_timed_mutex(const shared_timed_mutex&) = delete;
474 shared_timed_mutex& operator=(const shared_timed_mutex&) = delete;
476 // Exclusive ownership
478 void lock() { _Base::lock(); }
479 _GLIBCXX_NODISCARD bool try_lock() { return _Base::try_lock(); }
480 void unlock() { _Base::unlock(); }
482 template<typename _Rep, typename _Period>
485 try_lock_for(const chrono::duration<_Rep, _Period>& __rtime)
487 auto __rt = chrono::duration_cast<__clock_t::duration>(__rtime);
488 if (ratio_greater<__clock_t::period, _Period>())
490 return try_lock_until(__clock_t::now() + __rt);
495 void lock_shared() { _Base::lock_shared(); }
497 bool try_lock_shared() { return _Base::try_lock_shared(); }
498 void unlock_shared() { _Base::unlock_shared(); }
500 template<typename _Rep, typename _Period>
503 try_lock_shared_for(const chrono::duration<_Rep, _Period>& __rtime)
505 auto __rt = chrono::duration_cast<__clock_t::duration>(__rtime);
506 if (ratio_greater<__clock_t::period, _Period>())
508 return try_lock_shared_until(__clock_t::now() + __rt);
511#if _GLIBCXX_USE_PTHREAD_RWLOCK_T && _GTHREAD_USE_MUTEX_TIMEDLOCK
513 // Exclusive ownership
515 template<typename _Duration>
518 try_lock_until(const chrono::time_point<chrono::system_clock,
521 auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
522 auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
524 __gthread_time_t __ts =
526 static_cast<std::time_t>(__s.time_since_epoch().count()),
527 static_cast<long>(__ns.count())
530 int __ret = __glibcxx_rwlock_timedwrlock(&_M_rwlock, &__ts);
531 // On self-deadlock, we just fail to acquire the lock. Technically,
532 // the program violated the precondition.
533 if (__ret == ETIMEDOUT || __ret == EDEADLK)
535 // Errors not handled: EINVAL
536 __glibcxx_assert(__ret == 0);
540#ifdef _GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK
541 template<typename _Duration>
544 try_lock_until(const chrono::time_point<chrono::steady_clock,
547 auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
548 auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
550 __gthread_time_t __ts =
552 static_cast<std::time_t>(__s.time_since_epoch().count()),
553 static_cast<long>(__ns.count())
556 int __ret = pthread_rwlock_clockwrlock(&_M_rwlock, CLOCK_MONOTONIC,
558 // On self-deadlock, we just fail to acquire the lock. Technically,
559 // the program violated the precondition.
560 if (__ret == ETIMEDOUT || __ret == EDEADLK)
562 // Errors not handled: EINVAL
563 __glibcxx_assert(__ret == 0);
568 template<typename _Clock, typename _Duration>
571 try_lock_until(const chrono::time_point<_Clock, _Duration>& __atime)
573#if __cplusplus > 201703L
574 static_assert(chrono::is_clock_v<_Clock>);
576 // The user-supplied clock may not tick at the same rate as
577 // steady_clock, so we must loop in order to guarantee that
578 // the timeout has expired before returning false.
579 typename _Clock::time_point __now = _Clock::now();
581 auto __rtime = __atime - __now;
582 if (try_lock_for(__rtime))
584 __now = _Clock::now();
585 } while (__atime > __now);
591 template<typename _Duration>
594 try_lock_shared_until(const chrono::time_point<chrono::system_clock,
597 auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
598 auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
600 __gthread_time_t __ts =
602 static_cast<std::time_t>(__s.time_since_epoch().count()),
603 static_cast<long>(__ns.count())
607 // Unlike for lock(), we are not allowed to throw an exception so if
608 // the maximum number of read locks has been exceeded, or we would
609 // deadlock, we just try to acquire the lock again (and will time out
611 // In cases where we would exceed the maximum number of read locks
612 // throughout the whole time until the timeout, we will fail to
613 // acquire the lock even if it would be logically free; however, this
614 // is allowed by the standard, and we made a "strong effort"
615 // (see C++14 30.4.1.4p26).
616 // For cases where the implementation detects a deadlock we
617 // intentionally block and timeout so that an early return isn't
618 // mistaken for a spurious failure, which might help users realise
619 // there is a deadlock.
621 __ret = __glibcxx_rwlock_timedrdlock(&_M_rwlock, &__ts);
622 while (__ret == EAGAIN || __ret == EDEADLK);
623 if (__ret == ETIMEDOUT)
625 // Errors not handled: EINVAL
626 __glibcxx_assert(__ret == 0);
630#ifdef _GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK
631 template<typename _Duration>
634 try_lock_shared_until(const chrono::time_point<chrono::steady_clock,
637 auto __s = chrono::time_point_cast<chrono::seconds>(__atime);
638 auto __ns = chrono::duration_cast<chrono::nanoseconds>(__atime - __s);
640 __gthread_time_t __ts =
642 static_cast<std::time_t>(__s.time_since_epoch().count()),
643 static_cast<long>(__ns.count())
646 int __ret = pthread_rwlock_clockrdlock(&_M_rwlock, CLOCK_MONOTONIC,
648 // On self-deadlock, we just fail to acquire the lock. Technically,
649 // the program violated the precondition.
650 if (__ret == ETIMEDOUT || __ret == EDEADLK)
652 // Errors not handled: EINVAL
653 __glibcxx_assert(__ret == 0);
658 template<typename _Clock, typename _Duration>
661 try_lock_shared_until(const chrono::time_point<_Clock,
664#if __cplusplus > 201703L
665 static_assert(chrono::is_clock_v<_Clock>);
667 // The user-supplied clock may not tick at the same rate as
668 // steady_clock, so we must loop in order to guarantee that
669 // the timeout has expired before returning false.
670 typename _Clock::time_point __now = _Clock::now();
672 auto __rtime = __atime - __now;
673 if (try_lock_shared_for(__rtime))
675 __now = _Clock::now();
676 } while (__atime > __now);
680#else // ! (_GLIBCXX_USE_PTHREAD_RWLOCK_T && _GTHREAD_USE_MUTEX_TIMEDLOCK)
682 // Exclusive ownership
684 template<typename _Clock, typename _Duration>
687 try_lock_until(const chrono::time_point<_Clock, _Duration>& __abs_time)
689 unique_lock<mutex> __lk(_M_mut);
690 if (!_M_gate1.wait_until(__lk, __abs_time,
691 [=]{ return !_M_write_entered(); }))
695 _M_state |= _S_write_entered;
696 if (!_M_gate2.wait_until(__lk, __abs_time,
697 [=]{ return _M_readers() == 0; }))
699 _M_state ^= _S_write_entered;
700 // Wake all threads blocked while the write-entered flag was set.
701 _M_gate1.notify_all();
709 template <typename _Clock, typename _Duration>
712 try_lock_shared_until(const chrono::time_point<_Clock,
713 _Duration>& __abs_time)
715 unique_lock<mutex> __lk(_M_mut);
716 if (!_M_gate1.wait_until(__lk, __abs_time,
717 [=]{ return _M_state < _S_max_readers; }))
725#endif // _GLIBCXX_USE_PTHREAD_RWLOCK_T && _GTHREAD_USE_MUTEX_TIMEDLOCK
727#endif // _GLIBCXX_HAS_GTHREADS
730 template<typename _Mutex>
734 typedef _Mutex mutex_type;
738 shared_lock() noexcept : _M_pm(nullptr), _M_owns(false) { }
741 shared_lock(mutex_type& __m)
742 : _M_pm(std::__addressof(__m)), _M_owns(true)
743 { __m.lock_shared(); }
745 shared_lock(mutex_type& __m, defer_lock_t) noexcept
746 : _M_pm(std::__addressof(__m)), _M_owns(false) { }
748 shared_lock(mutex_type& __m, try_to_lock_t)
749 : _M_pm(std::__addressof(__m)), _M_owns(__m.try_lock_shared()) { }
751 shared_lock(mutex_type& __m, adopt_lock_t)
752 : _M_pm(std::__addressof(__m)), _M_owns(true) { }
754 template<typename _Clock, typename _Duration>
755 shared_lock(mutex_type& __m,
756 const chrono::time_point<_Clock, _Duration>& __abs_time)
757 : _M_pm(std::__addressof(__m)),
758 _M_owns(__m.try_lock_shared_until(__abs_time)) { }
760 template<typename _Rep, typename _Period>
761 shared_lock(mutex_type& __m,
762 const chrono::duration<_Rep, _Period>& __rel_time)
763 : _M_pm(std::__addressof(__m)),
764 _M_owns(__m.try_lock_shared_for(__rel_time)) { }
769 _M_pm->unlock_shared();
772 shared_lock(shared_lock const&) = delete;
773 shared_lock& operator=(shared_lock const&) = delete;
775 shared_lock(shared_lock&& __sl) noexcept : shared_lock()
779 operator=(shared_lock&& __sl) noexcept
781 shared_lock(std::move(__sl)).swap(*this);
789 _M_pm->lock_shared();
798 return _M_owns = _M_pm->try_lock_shared();
801 template<typename _Rep, typename _Period>
804 try_lock_for(const chrono::duration<_Rep, _Period>& __rel_time)
807 return _M_owns = _M_pm->try_lock_shared_for(__rel_time);
810 template<typename _Clock, typename _Duration>
813 try_lock_until(const chrono::time_point<_Clock, _Duration>& __abs_time)
816 return _M_owns = _M_pm->try_lock_shared_until(__abs_time);
823 __throw_system_error(int(errc::operation_not_permitted));
824 _M_pm->unlock_shared();
831 swap(shared_lock& __u) noexcept
833 std::swap(_M_pm, __u._M_pm);
834 std::swap(_M_owns, __u._M_owns);
841 return std::__exchange(_M_pm, nullptr);
847 bool owns_lock() const noexcept { return _M_owns; }
849 explicit operator bool() const noexcept { return _M_owns; }
852 mutex_type* mutex() const noexcept { return _M_pm; }
858 if (_M_pm == nullptr)
859 __throw_system_error(int(errc::operation_not_permitted));
861 __throw_system_error(int(errc::resource_deadlock_would_occur));
868 /// Swap specialization for shared_lock
869 /// @relates shared_mutex
870 template<typename _Mutex>
872 swap(shared_lock<_Mutex>& __x, shared_lock<_Mutex>& __y) noexcept
876_GLIBCXX_END_NAMESPACE_VERSION
881#endif // _GLIBCXX_SHARED_MUTEX