enum class
<future>
std::launchLaunching policy for async
Thisenum class
type is a bitmask type that defines the launching policy in calls to async.
It can be any combination of the following values:
launch labelint
value description launch::async unspecified Asynchronous: The function is called asynchronously by a new thread and synchronizes its return with the point of access to the shared state. launch::deferred unspecified Deferred: The function is called at the point of access to the shared state. The unspecified equivalent int
values shall denote individual bits, allowing several labels to be combined in a single bitmask. When multiple values of this type are combined, the function automatically selects one (depending on their particular library implementation).
Library implementations may define additional labels of this type for different launching policies that may describe restrictions on task interaction by different calls.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// launch::async vs launch::deferred
#include <iostream> // std::cout
#include <future> // std::async, std::future, std::launch
#include <chrono> // std::chrono::milliseconds
#include <thread> // std::this_thread::sleep_for
void print_ten (char c, int ms) {
for (int i=0; i<10; ++i) {
std::this_thread::sleep_for (std::chrono::milliseconds(ms));
std::cout << c;
}
}
int main ()
{
std::cout << "with launch::async:\n";
std::future<void> foo = std::async (std::launch::async,print_ten,'*',100);
std::future<void> bar = std::async (std::launch::async,print_ten,'@',200);
// async "get" (wait for foo and bar to be ready):
foo.get();
bar.get();
std::cout << "\n\n";
std::cout << "with launch::deferred:\n";
foo = std::async (std::launch::deferred,print_ten,'*',100);
bar = std::async (std::launch::deferred,print_ten,'@',200);
// deferred "get" (perform the actual calls):
foo.get();
bar.get();
std::cout << '\n';
return 0;
}
with launch::async: **@**@**@*@**@*@@@@@ with launch::deferred: **********@@@@@@@@@@
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4