std::shared_mutex (3) - Linux Manuals
std::shared_mutex: std::shared_mutex
NAME
std::shared_mutex - std::shared_mutex
Synopsis
Defined in header <shared_mutex>
class shared_mutex; (since C++17)
The shared_mutex class is a synchronization primitive that can be used to protect shared data from being simultaneously accessed by multiple threads. In contrast to other mutex types which facilitate exclusive access, a shared_mutex has two levels of access:
* shared - several threads can share ownership of the same mutex.
* exclusive - only one thread can own the mutex.
Shared mutexes are usually used in situations when multiple readers can access the same resource at the same time without causing data races, but only one writer can do so.
The shared_mutex class satisfies all requirements of SharedMutex and StandardLayoutType.
Member types
Member type Definition
native_handle_type(optional) implementation-defined
Member functions
constructor (public member function)
destructor (public member function)
operator= not copy-assignable
[deleted]
Exclusive locking
lock (public member function)
try_lock (public member function)
unlock (public member function)
Shared locking
lock_shared (public member function)
try_lock_shared (public member function)
unlock_shared (public member function)
Native handle
native_handle (public member function)
Example
// Run this code