# C++ named requirements: Lockable (since C++11)

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

The Lockable requirements extends the BasicLockable requirements to include attempted locking.

## Official Specification Summary (cppreference)

The *Lockable* requirements extends the *BasicLockable* requirements to include attempted locking.

### Requirements

- *BasicLockable*

For type `L` to be *Lockable*, it must meet the above condition as well as the following:

| Expression | Effects | Return value |
| --- | --- | --- |
| `m.try_lock()` | Attempts to acquire the 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 acquired, `false` otherwise |

### Notes

The `try_lock` member functions obtains a non-shared lock on `m` on success.

### Standard library

The following standard library types satisfy *Lockable* requirements:

- `mutex` (C++11): provides basic mutual exclusion facility (class)
- `recursive_mutex` (C++11): provides mutual exclusion facility which can be locked recursively by the same thread (class)
- `recursive_timed_mutex` (C++11): provides mutual exclusion facility which can be locked recursively by the same thread and implements locking with a timeout (class)
- `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)
- `timed_mutex` (C++11): provides mutual exclusion facility which implements locking with a timeout (class)

### See also

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

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