#include #include #include using namespace std; /* LatexBeginR */ void receptionist(promise say_welcome, future errand, promise reply) { cout << "R: Welcome, how can I help you?" << endl; say_welcome.set_value(); string name = errand.get(); cout << "R: Please enter, " << name << " is expecting you." << endl; reply.set_value(); } /* LatexEndR */ /* LatexBeginV */ void visitor(future get_welcome, promise tell_errand, future get_reply) { string name{"Mr X"}; get_welcome.wait(); cout << "V: Hi, I'm here to meet " << name << endl; tell_errand.set_value(name); get_reply.wait(); cout << "V: Thank you" << endl; } /* LatexEndV */ int main() { /* LatexBeginMain */ promise say_welcome; promise say_errand; promise reply; // You have to get the futures before you move the promise future get_welcome = say_welcome.get_future(); future get_errand = say_errand.get_future(); future get_reply = reply.get_future(); // You have to move promises and futures into the threads thread r(receptionist, move(say_welcome), move(get_errand), move(reply)); thread v(visitor, move(get_welcome), move(say_errand), move(get_reply)); // Wait for both threads to finish before continuing r.join(); v.join(); cout << "Main done" << endl; /* LatexEndMain */ }