Since C++14 we have synchronization objects that can be used to protect shared data from being simultaneously accessed by multiple threads. In contrast to basic mutex and lock types which facilitate exclusive access, shared mutexes and locks has two levels of access:
- shared - several threads can share ownership of the same mutex.
- exclusive - only one thread can own the mutex.
If one thread has acquired the exclusive lock, no other threads can acquire the lock (including the shared).
If one thread has acquired the shared lock, no other thread can acquire the exclusive lock, but can acquire the shared lock.