tmp/tmp4wvcj9mo/{from.md → to.md}
RENAMED
|
@@ -18,57 +18,49 @@ to initialize data without causing a data race or deadlock.
|
|
| 18 |
|
| 19 |
``` cpp
|
| 20 |
constexpr once_flag() noexcept;
|
| 21 |
```
|
| 22 |
|
| 23 |
-
*Effects:* Constructs an object of type `once_flag`.
|
| 24 |
-
|
| 25 |
*Synchronization:* The construction of a `once_flag` object is not
|
| 26 |
synchronized.
|
| 27 |
|
| 28 |
-
*
|
| 29 |
invocation of `call_once` with the object as its initial argument that
|
| 30 |
no function has been called.
|
| 31 |
|
| 32 |
#### Function `call_once` <a id="thread.once.callonce">[[thread.once.callonce]]</a>
|
| 33 |
|
| 34 |
``` cpp
|
| 35 |
template<class Callable, class... Args>
|
| 36 |
void call_once(once_flag& flag, Callable&& func, Args&&... args);
|
| 37 |
```
|
| 38 |
|
| 39 |
-
*
|
| 40 |
-
|
| 41 |
-
``` cpp
|
| 42 |
-
INVOKE(std::forward<Callable>(func), std::forward<Args>(args)...)
|
| 43 |
-
```
|
| 44 |
-
|
| 45 |
-
(see [[func.require]]) shall be a valid expression.
|
| 46 |
|
| 47 |
*Effects:* An execution of `call_once` that does not call its `func` is
|
| 48 |
a *passive* execution. An execution of `call_once` that calls its `func`
|
| 49 |
-
is an *active* execution. An active execution
|
| 50 |
std::forward\<Callable\>(func), std::forward\<Args\>(args)...). If such
|
| 51 |
a call to `func` throws an exception the execution is *exceptional*,
|
| 52 |
-
otherwise it is *returning*. An exceptional execution
|
| 53 |
-
|
| 54 |
-
`call_once` for any given `once_flag`: at most one
|
| 55 |
-
execution; if there is a returning execution, it
|
| 56 |
-
|
| 57 |
-
|
| 58 |
|
| 59 |
[*Note 1*: Passive executions allow other threads to reliably observe
|
| 60 |
the results produced by the earlier returning execution. — *end note*]
|
| 61 |
|
| 62 |
*Synchronization:* For any given `once_flag`: all active executions
|
| 63 |
occur in a total order; completion of an active execution synchronizes
|
| 64 |
-
with
|
| 65 |
order; and the returning execution synchronizes with the return from all
|
| 66 |
passive executions.
|
| 67 |
|
| 68 |
*Throws:* `system_error` when an exception is
|
| 69 |
-
required
|
| 70 |
|
| 71 |
[*Example 1*:
|
| 72 |
|
| 73 |
``` cpp
|
| 74 |
// global flag, regular function
|
|
|
|
| 18 |
|
| 19 |
``` cpp
|
| 20 |
constexpr once_flag() noexcept;
|
| 21 |
```
|
| 22 |
|
|
|
|
|
|
|
| 23 |
*Synchronization:* The construction of a `once_flag` object is not
|
| 24 |
synchronized.
|
| 25 |
|
| 26 |
+
*Ensures:* The object’s internal state is set to indicate to an
|
| 27 |
invocation of `call_once` with the object as its initial argument that
|
| 28 |
no function has been called.
|
| 29 |
|
| 30 |
#### Function `call_once` <a id="thread.once.callonce">[[thread.once.callonce]]</a>
|
| 31 |
|
| 32 |
``` cpp
|
| 33 |
template<class Callable, class... Args>
|
| 34 |
void call_once(once_flag& flag, Callable&& func, Args&&... args);
|
| 35 |
```
|
| 36 |
|
| 37 |
+
*Mandates:* `is_invocable_v<Callable, Args...>` is `true`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
*Effects:* An execution of `call_once` that does not call its `func` is
|
| 40 |
a *passive* execution. An execution of `call_once` that calls its `func`
|
| 41 |
+
is an *active* execution. An active execution calls *INVOKE*(
|
| 42 |
std::forward\<Callable\>(func), std::forward\<Args\>(args)...). If such
|
| 43 |
a call to `func` throws an exception the execution is *exceptional*,
|
| 44 |
+
otherwise it is *returning*. An exceptional execution propagates the
|
| 45 |
+
exception to the caller of `call_once`. Among all executions of
|
| 46 |
+
`call_once` for any given `once_flag`: at most one is a returning
|
| 47 |
+
execution; if there is a returning execution, it is the last active
|
| 48 |
+
execution; and there are passive executions only if there is a returning
|
| 49 |
+
execution.
|
| 50 |
|
| 51 |
[*Note 1*: Passive executions allow other threads to reliably observe
|
| 52 |
the results produced by the earlier returning execution. — *end note*]
|
| 53 |
|
| 54 |
*Synchronization:* For any given `once_flag`: all active executions
|
| 55 |
occur in a total order; completion of an active execution synchronizes
|
| 56 |
+
with [[intro.multithread]] the start of the next one in this total
|
| 57 |
order; and the returning execution synchronizes with the return from all
|
| 58 |
passive executions.
|
| 59 |
|
| 60 |
*Throws:* `system_error` when an exception is
|
| 61 |
+
required [[thread.req.exception]], or any exception thrown by `func`.
|
| 62 |
|
| 63 |
[*Example 1*:
|
| 64 |
|
| 65 |
``` cpp
|
| 66 |
// global flag, regular function
|