[thread.condition.general]

# 32 Concurrency support library [[thread]](./#thread)

## 32.7 Condition variables [[thread.condition]](thread.condition#general)

### 32.7.1 General [thread.condition.general]

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L9482)

Condition variables provide synchronization primitives used to block a thread until
notified by some other thread that some condition is met or until a system time is
reached[.](#1.sentence-1)

Class condition_variable provides a condition variable that can only
wait on an object of type unique_lock<mutex>, allowing the implementation
to be more efficient[.](#1.sentence-2)

Class condition_variable_any provides a general
condition variable that can wait on objects of user-supplied lock types[.](#1.sentence-3)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L9490)

Condition variables permit concurrent invocation of the wait, wait_for,wait_until, notify_one and notify_all member functions[.](#2.sentence-1)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L9494)

The executions of notify_one and notify_all are atomic[.](#3.sentence-1)

The executions of wait, wait_for, and wait_until are performed
in three atomic parts:

| [1.](#3.1) | the release of the mutex and entry into the waiting state; |
| --- | --- |
| [2.](#3.2) | the unblocking of the wait; and |
| [3.](#3.3) | the reacquisition of the lock[.](#3.sentence-2) |

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L9505)

The implementation behaves as if all executions of notify_one, notify_all, and each
part of the wait, wait_for, and wait_until executions are
executed in a single unspecified total order consistent with the âhappens beforeâ order[.](#4.sentence-1)

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L9510)

Condition variable construction and destruction need not be synchronized[.](#5.sentence-1)
