tmp/tmpvg8oe33p/{from.md → to.md}
RENAMED
|
@@ -4,15 +4,13 @@ The function template `async` provides a mechanism to launch a function
|
|
| 4 |
potentially in a new thread and provides the result of the function in a
|
| 5 |
`future` object with which it shares a shared state.
|
| 6 |
|
| 7 |
``` cpp
|
| 8 |
template <class F, class... Args>
|
| 9 |
-
future<
|
| 10 |
-
async(F&& f, Args&&... args);
|
| 11 |
template <class F, class... Args>
|
| 12 |
-
future<
|
| 13 |
-
async(launch policy, F&& f, Args&&... args);
|
| 14 |
```
|
| 15 |
|
| 16 |
*Requires:* `F` and each `Ti` in `Args` shall satisfy the
|
| 17 |
`MoveConstructible` requirements.
|
| 18 |
*`INVOKE`*`(`*`DECAY_COPY`*`(std::forward<F>(f)), `*`DECAY_COPY`*`(std::forward<Args>(args))...)`
|
|
@@ -41,28 +39,37 @@ implementation may choose any of the corresponding policies):
|
|
| 41 |
asynchronous return objects that reference that state.
|
| 42 |
- if `policy & launch::deferred` is non-zero — Stores
|
| 43 |
*`DECAY_COPY`*`(std::forward<F>(f))` and
|
| 44 |
*`DECAY_COPY`*`(std::forward<Args>(args))...` in the shared state.
|
| 45 |
These copies of `f` and `args` constitute a *deferred function*.
|
| 46 |
-
Invocation of the deferred function evaluates
|
| 47 |
-
|
| 48 |
-
and `xyz` is the stored
|
| 49 |
-
*`DECAY_COPY`*`(std::forward<Args>(args))...`.
|
|
|
|
|
|
|
|
|
|
| 50 |
made ready until the function has completed. The first call to a
|
| 51 |
non-timed waiting function ([[futures.state]]) on an asynchronous
|
| 52 |
return object referring to this shared state shall invoke the deferred
|
| 53 |
function in the thread that called the waiting function. Once
|
| 54 |
-
evaluation of *`INVOKE`*`(g, xyz)` begins, the
|
| 55 |
-
considered deferred. If this policy is specified
|
| 56 |
-
policies, such as when using a `policy` value of
|
| 57 |
`launch::async | launch::deferred`, implementations should defer
|
| 58 |
invocation or the selection of the policy when no more concurrency can
|
| 59 |
be effectively exploited.
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
*Returns:* An object of type
|
| 62 |
-
`future<
|
| 63 |
-
state created by this call to `async`.
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
*Synchronization:* Regardless of the provided `policy` argument,
|
| 66 |
|
| 67 |
- the invocation of `async` synchronizes with ([[intro.multithread]])
|
| 68 |
the invocation of `f`. This statement applies even when the
|
|
@@ -73,29 +80,26 @@ state created by this call to `async`.
|
|
| 73 |
|
| 74 |
If the implementation chooses the `launch::async` policy,
|
| 75 |
|
| 76 |
- a call to a waiting function on an asynchronous return object that
|
| 77 |
shares the shared state created by this `async` call shall block until
|
| 78 |
-
the associated thread has completed, as if
|
| 79 |
-
|
| 80 |
- the associated thread completion synchronizes
|
| 81 |
with ([[intro.multithread]]) the return from the first function that
|
| 82 |
successfully detects the ready status of the shared state or with the
|
| 83 |
return from the last function that releases the shared state,
|
| 84 |
whichever happens first.
|
| 85 |
|
| 86 |
-
*Throws:* `system_error` if `policy
|
| 87 |
implementation is unable to start a new thread.
|
| 88 |
|
| 89 |
*Error conditions:*
|
| 90 |
|
| 91 |
-
- `resource_unavailable_try_again` — if `policy
|
| 92 |
the system is unable to start a new thread.
|
| 93 |
|
| 94 |
-
*Remarks:* The first signature shall not participate in overload
|
| 95 |
-
resolution if `decay<F>::type` is `std::launch`.
|
| 96 |
-
|
| 97 |
``` cpp
|
| 98 |
int work1(int value);
|
| 99 |
int work2(int value);
|
| 100 |
int work(int value) {
|
| 101 |
auto handle = std::async([=]{ return work2(value); });
|
|
|
|
| 4 |
potentially in a new thread and provides the result of the function in a
|
| 5 |
`future` object with which it shares a shared state.
|
| 6 |
|
| 7 |
``` cpp
|
| 8 |
template <class F, class... Args>
|
| 9 |
+
future<result_of_t<decay_t<F>(decay_t<Args>...)>> async(F&& f, Args&&... args);
|
|
|
|
| 10 |
template <class F, class... Args>
|
| 11 |
+
future<result_of_t<decay_t<F>(decay_t<Args>...)>> async(launch policy, F&& f, Args&&... args);
|
|
|
|
| 12 |
```
|
| 13 |
|
| 14 |
*Requires:* `F` and each `Ti` in `Args` shall satisfy the
|
| 15 |
`MoveConstructible` requirements.
|
| 16 |
*`INVOKE`*`(`*`DECAY_COPY`*`(std::forward<F>(f)), `*`DECAY_COPY`*`(std::forward<Args>(args))...)`
|
|
|
|
| 39 |
asynchronous return objects that reference that state.
|
| 40 |
- if `policy & launch::deferred` is non-zero — Stores
|
| 41 |
*`DECAY_COPY`*`(std::forward<F>(f))` and
|
| 42 |
*`DECAY_COPY`*`(std::forward<Args>(args))...` in the shared state.
|
| 43 |
These copies of `f` and `args` constitute a *deferred function*.
|
| 44 |
+
Invocation of the deferred function evaluates
|
| 45 |
+
*`INVOKE`*`(std::move(g), std::move(xyz))` where `g` is the stored
|
| 46 |
+
value of *`DECAY_COPY`*`(std::forward<F>(f))` and `xyz` is the stored
|
| 47 |
+
copy of *`DECAY_COPY`*`(std::forward<Args>(args))...`. Any return
|
| 48 |
+
value is stored as the result in the shared state. Any exception
|
| 49 |
+
propagated from the execution of the deferred function is stored as
|
| 50 |
+
the exceptional result in the shared state. The shared state is not
|
| 51 |
made ready until the function has completed. The first call to a
|
| 52 |
non-timed waiting function ([[futures.state]]) on an asynchronous
|
| 53 |
return object referring to this shared state shall invoke the deferred
|
| 54 |
function in the thread that called the waiting function. Once
|
| 55 |
+
evaluation of *`INVOKE`*`(std::move(g), std::move(xyz))` begins, the
|
| 56 |
+
function is no longer considered deferred. If this policy is specified
|
| 57 |
+
together with other policies, such as when using a `policy` value of
|
| 58 |
`launch::async | launch::deferred`, implementations should defer
|
| 59 |
invocation or the selection of the policy when no more concurrency can
|
| 60 |
be effectively exploited.
|
| 61 |
+
- If no value is set in the launch policy, or a value is set that is
|
| 62 |
+
neither specified in this International Standard or by the
|
| 63 |
+
implementation, the behaviour is undefined.
|
| 64 |
|
| 65 |
*Returns:* An object of type
|
| 66 |
+
`future<result_of_t<decay_t<F>(decay_t<Args>...)>``>` that refers to the
|
| 67 |
+
shared state created by this call to `async`. If a future obtained from
|
| 68 |
+
std::async is moved outside the local scope, other code that uses the
|
| 69 |
+
future must be aware that the future’s destructor may block for the
|
| 70 |
+
shared state to become ready.
|
| 71 |
|
| 72 |
*Synchronization:* Regardless of the provided `policy` argument,
|
| 73 |
|
| 74 |
- the invocation of `async` synchronizes with ([[intro.multithread]])
|
| 75 |
the invocation of `f`. This statement applies even when the
|
|
|
|
| 80 |
|
| 81 |
If the implementation chooses the `launch::async` policy,
|
| 82 |
|
| 83 |
- a call to a waiting function on an asynchronous return object that
|
| 84 |
shares the shared state created by this `async` call shall block until
|
| 85 |
+
the associated thread has completed, as if joined, or else time
|
| 86 |
+
out ([[thread.thread.member]]);
|
| 87 |
- the associated thread completion synchronizes
|
| 88 |
with ([[intro.multithread]]) the return from the first function that
|
| 89 |
successfully detects the ready status of the shared state or with the
|
| 90 |
return from the last function that releases the shared state,
|
| 91 |
whichever happens first.
|
| 92 |
|
| 93 |
+
*Throws:* `system_error` if `policy == launch::async` and the
|
| 94 |
implementation is unable to start a new thread.
|
| 95 |
|
| 96 |
*Error conditions:*
|
| 97 |
|
| 98 |
+
- `resource_unavailable_try_again` — if `policy == launch::async` and
|
| 99 |
the system is unable to start a new thread.
|
| 100 |
|
|
|
|
|
|
|
|
|
|
| 101 |
``` cpp
|
| 102 |
int work1(int value);
|
| 103 |
int work2(int value);
|
| 104 |
int work(int value) {
|
| 105 |
auto handle = std::async([=]{ return work2(value); });
|