104 lines
2.7 KiB
Markdown
104 lines
2.7 KiB
Markdown
[atomics.wait]
|
||
|
||
# 32 Concurrency support library [[thread]](./#thread)
|
||
|
||
## 32.5 Atomic operations [[atomics]](atomics#wait)
|
||
|
||
### 32.5.6 Waiting and notifying [atomics.wait]
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L3144)
|
||
|
||
[*Atomic waiting operations*](#def:atomic,waiting_operation "32.5.6 Waiting and notifying [atomics.wait]") and [*atomic notifying operations*](#def:atomic,notifying_operation "32.5.6 Waiting and notifying [atomics.wait]") provide a mechanism to wait for the value of an atomic object to change
|
||
more efficiently than can be achieved with polling[.](#1.sentence-1)
|
||
|
||
An atomic waiting operation may block until it is unblocked
|
||
by an atomic notifying operation, according to each function's effects[.](#1.sentence-2)
|
||
|
||
[*Note [1](#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[.](#1.sentence-3)
|
||
|
||
â *end note*]
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L3157)
|
||
|
||
[*Note [2](#note-2)*:
|
||
|
||
The following functions are atomic waiting operations:
|
||
|
||
- [(2.1)](#2.1)
|
||
|
||
atomic<T>::wait,
|
||
|
||
- [(2.2)](#2.2)
|
||
|
||
atomic_flag::wait,
|
||
|
||
- [(2.3)](#2.3)
|
||
|
||
atomic_wait and atomic_wait_explicit,
|
||
|
||
- [(2.4)](#2.4)
|
||
|
||
atomic_flag_wait and atomic_flag_wait_explicit, and
|
||
|
||
- [(2.5)](#2.5)
|
||
|
||
atomic_ref<T>::wait[.](#2.sentence-1)
|
||
|
||
â *end note*]
|
||
|
||
[3](#3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L3169)
|
||
|
||
[*Note [3](#note-3)*:
|
||
|
||
The following functions are atomic notifying operations:
|
||
|
||
- [(3.1)](#3.1)
|
||
|
||
atomic<T>::notify_one and atomic<T>::notify_all,
|
||
|
||
- [(3.2)](#3.2)
|
||
|
||
atomic_flag::notify_one and atomic_flag::notify_all,
|
||
|
||
- [(3.3)](#3.3)
|
||
|
||
atomic_notify_one and atomic_notify_all,
|
||
|
||
- [(3.4)](#3.4)
|
||
|
||
atomic_flag_notify_one and atomic_flag_notify_all, and
|
||
|
||
- [(3.5)](#3.5)
|
||
|
||
atomic_ref<T>::notify_one and atomic_ref<T>::notify_all[.](#3.sentence-1)
|
||
|
||
â *end note*]
|
||
|
||
[4](#4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L3182)
|
||
|
||
A call to an atomic waiting operation on an atomic object M is [*eligible to be unblocked*](#def:eligible_to_be_unblocked "32.5.6 Waiting and notifying [atomics.wait]") by a call to an atomic notifying operation on M if there exist side effects X and Y on M such that:
|
||
|
||
- [(4.1)](#4.1)
|
||
|
||
the atomic waiting operation has blocked after observing the result of X,
|
||
|
||
- [(4.2)](#4.2)
|
||
|
||
X precedes Y in the modification order of M, and
|
||
|
||
- [(4.3)](#4.3)
|
||
|
||
Y happens before the call to the atomic notifying operation[.](#4.sentence-1)
|