May 2017
Intermediate to advanced
590 pages
17h 18m
English
We will use futures, so read the previous recipe to get a quick overview of how they work. Both async() and future are available in the std namespace in the <future> header.
For the examples in this recipe, we will use the following functions:
void do_something() { // simulate long running operation { using namespace std::chrono_literals; std::this_thread::sleep_for(2s); } std::lock_guard<std::mutex> lock(g_mutex); std::cout << "operation 1 done" << std::endl; } void do_something_else() { // simulate long running operation { using namespace std::chrono_literals; std::this_thread::sleep_for(1s); } std::lock_guard<std::mutex> lock(g_mutex); std::cout << "operation 2 done" << std::endl; } int compute_something() { // simulate ...Read now
Unlock full access