32 Concurrency support library [thread] (original) (raw)
32.5 Atomic operations [atomics]
32.5.6 Waiting and notifying [atomics.wait]
Atomic waiting operationsand atomic notifying operationsprovide a mechanism to wait for the value of an atomic object to change more efficiently than can be achieved with polling.
An atomic waiting operation may block until it is unblocked by an atomic notifying operation, according to each function's effects.
[Note 1:
Programs are not guaranteed to observe transient atomic values, an issue known as the A-B-A problem, resulting in continued blocking if a condition is only temporarily met.
— _end note_]
[Note 2:
The following functions are atomic waiting operations:
- atomic<T>::wait,
- atomic_flag::wait,
- atomic_wait and atomic_wait_explicit,
- atomic_flag_wait and atomic_flag_wait_explicit, and
- atomic_ref<T>::wait.
— _end note_]
[Note 3:
The following functions are atomic notifying operations:
- atomic<T>::notify_one and atomic<T>::notify_all,
- atomic_flag::notify_one and atomic_flag::notify_all,
- atomic_notify_one and atomic_notify_all,
- atomic_flag_notify_one and atomic_flag_notify_all, and
- atomic_ref<T>::notify_one and atomic_ref<T>::notify_all.
— _end note_]
A call to an atomic waiting operation on an atomic object Mis eligible to be unblockedby a call to an atomic notifying operation on Mif there exist side effects X and Y on M such that:
- the atomic waiting operation has blocked after observing the result of X,
- X precedes Y in the modification order of M, and
- Y happens before the call to the atomic notifying operation.