# C++ named requirements: SharedLockable (since C++14)

> C++ Atlas: `cppatlas.com/w/cpp/named_req/SharedLockable` | Source: https://en.cppreference.com/w/cpp/named_req/SharedLockable | Domain: Named Requirements | Standards: C++14, C++17

The SharedLockable requirements describe the minimal characteristics of types that provide shared blocking semantics for execution agents (i.e. threads).

## Official Specification Summary (cppreference)

The *SharedLockable* requirements describe the minimal characteristics of types that provide shared blocking semantics for execution agents (i.e. threads).

### Requirements

For type `L` to be *SharedLockable*, the following conditions have to be satisfied for an object `m` of type `L`:

| Expression | Preconditions | Effects | Return value |
| --- | --- | --- | --- |
| `m.lock_shared()` |   | Blocks until a lock can be obtained for the current execution agent (thread, process, task). If an exception is thrown, no lock is obtained. |   |
| `m.try_lock_shared()` |   | Attempts to obtain a lock for the current execution agent (thread, process, task) without blocking. If an exception is thrown, no lock is obtained. | `true` if the lock was obtained, `false` otherwise |
| `m.unlock_shared()` | The current execution agent holds a shared lock on `m`. | Releases the shared lock held by the execution agent. Throws no exceptions. |   |

#### Shared locks

A lock on an object is said to be *shared lock* if it is acquired by a call to `lock_shared`, `try_lock_shared`, `try_lock_shared_for`, or `try_lock_shared_until` member function.

### Standard library

The following standard library types satisfy *SharedLockable* requirements:

- `shared_mutex` (C++17): provides shared mutual exclusion facility (class)
- `shared_timed_mutex` (C++14): provides shared mutual exclusion facility and implements locking with a timeout (class)

### See also

- [Thread support library](https://en.cppreference.com/w/cpp/thread)
- [*SharedTimedLockable*](https://en.cppreference.com/w/cpp/named_req/SharedTimedLockable)
- [*SharedMutex*](https://en.cppreference.com/w/cpp/named_req/SharedMutex)

---
Attribution: content from https://en.cppreference.com/w/cpp/named_req/SharedLockable (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.