Daily bit(e) of C++ | std::shared_mutex
Daily bit(e) of C++ ♻️15, A mutex variant that supports exclusive and shared locks: std::shared_mutex.
The std::shared_mutex is a std::mutex variant that supports two types of locks: an exclusive lock that can be held by only one thread and a shared lock that can be held by any number of threads (as long as the exclusive lock is not held).
The typical use case for exclusive/shared lock semantics is a shared resource with read/write access. A mutating operation requires exclusive access to the resource, while non-mutating operations can co-exist (run in parallel) with other non-mutating operations.