31 Atomic operations library [atomics]

31.6 Waiting and notifying [atomics.wait]

Atomic waiting operations and atomic notifying operations provide 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 M is eligible to be unblocked by a call to an atomic notifying operation on M if 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.