May 2017
Intermediate to advanced
590 pages
17h 18m
English
To communicate a value from one thread to another through promises and futures, do this:
void produce_value(std::promise<int>& p) { // simulate long running operation { using namespace std::chrono_literals; std::this_thread::sleep_for(2s); } // continued at 2. }
// continued from 1. p.set_value(42);
void consume_value(std::future<int>& f) { // continued at 4. }
Read now
Unlock full access