std::shared_timed_mutex::lock_shared

From cppreference.com
Concurrency support library
Threads
(C++11)
(C++20)
this_thread namespace
(C++11)
(C++11)
(C++11)
(C++11)
Cooperative cancellation
Mutual exclusion
(C++11)
(C++11)
(C++17)
Generic lock management
(C++11)
(C++11)
(C++17)
(C++11)
(C++14)
(C++11)
(C++11)
(C++11)
(C++11) (C++11) (C++11) (C++11) (C++11) (C++11)
Condition variables
(C++11)
Semaphores
Latches and Barriers
(C++20)
(C++20)
Futures
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Safe Reclamation
(C++26)
(C++26)
(C++26)
Hazard Pointers
(C++26)
Atomic types
(C++11)
(C++20)
(C++11)
Initialization of atomic types
(C++11)(deprecated in C++20)
(C++11)(deprecated in C++20)
Memory ordering
(C++11)
(C++11)
Free functions for atomic operations
Free functions for atomic flags
void lock_shared();
(since C++14)

Acquires shared ownership of the mutex. If another thread is holding the mutex in exclusive ownership, a call to lock_shared will block execution until shared ownership can be acquired.

If lock_shared is called by a thread that already owns the mutex in any mode (exclusive or shared), the behavior is undefined.

If more than the implementation-defined maximum number of shared owners already locked the mutex in shared mode, lock_shared

Prior unlock() operation on the same mutex synchronizes-with (as defined in std::memory_order

Parameters

(none)

Return value

(none)

Exceptions

Throws std::system_error when errors occur, including errors from the underlying operating system that would prevent lock

Notes

lock_shared() is usually not called directly: std::shared_lock is used to manage shared locking.

Example

See also

locks the mutex, blocks if the mutex is not available
(public member function)
tries to lock the mutex for shared ownership, returns if the mutex is not available
(public member function)
unlocks the mutex (shared ownership)
(public member function)