...

/

Types of Locks: std::shared_lock

Types of Locks: std::shared_lock

This lesson gives an overview of the std::shared_lock which is a type of lock used in C++.

An std::shared_lock has the same interface as an std::unique_lock but behaves differently when used with an std::shared_timed_mutex. Many threads can share one std::shared_timed_mutex and, therefore, implement a reader-writer lock. The idea of reader-writer locks is straightforward and extremely useful. An arbitrary number of threads executing read operations can access the critical region at the same time, but only one thread is allowed to write.

Reader-writer locks do not solve the fundamental problem - threads competing for access to a critical region but they do help to minimize the bottleneck. ...