[...] int getRandomTime(int start, int end){ random_device seed; mt19937 engine(seed()); uniform_int_distribution dist(start,end); return dist(engine); }; class Worker{ public: Worker(string n):name(n){}; void operator() (promise&& preparedWork, shared_future boss2WorkerStartWork, promise&& doneWork, shared_futureboss2WorkerGoHome ){ // prepare the work and notfiy the boss int prepareTime= getRandomTime(500,2000); sleep_for(milliseconds(prepareTime)); preparedWork.set_value(); cout << name << ": " << "Work prepared after " << prepareTime << " milliseconds." << endl; // still waiting for the permission to start working boss2WorkerStartWork.wait(); // do the work and notify the boss int workTime= getRandomTime(200,400); sleep_for(milliseconds(workTime)); doneWork.set_value(); cout << name << ": " << "Work done after " << workTime << " milliseconds." << endl; // still waiting for the permission to go home boss2WorkerGoHome.wait(); } private: string name; }; int main(){ cout << endl; // define the promise => Instruction from the boss promise startWorkPromise; promise goHomePromise; // get the shared futures from the promise shared_future startWorkFuture= startWorkPromise.get_future(); shared_future goHomeFuture= goHomePromise.get_future(); promise herbPrepared; future waitForHerbPrepared= herbPrepared.get_future(); promise herbDone; future waitForHerbDone= herbDone.get_future(); Worker herb(" Herb"); thread herbWork(herb,move(herbPrepared),startWorkFuture,move(herbDone),goHomeFuture); // start thread scott, bjarne, andrei, andrew and david [...] cout << "BOSS: PREPARE YOUR WORK.\n " << endl; // waiting for the worker waitForHerbPrepared.wait(), waitForScottPrepared.wait(), waitForBjarnePrepared.wait(), waitForAndreiPrepared.wait(), waitForAndrewPrepared.wait(), waitForDavidPrepared.wait(); // notify the worker about the begin of the work cout << "\nBOSS: START YOUR WORK. \n" << endl; startWorkPromise.set_value(); // waiting for the worker waitForHerbDone.wait(), waitForScottDone.wait(), waitForBjarneDone.wait(), waitForAndreiDone.wait(), waitForAndrewDone.wait(), waitForDavidDone.wait(); // notify the worker about the end of the work cout << "\nBOSS: GO HOME. \n" << endl; goHomePromise.set_value(); herbWork.join(); scottWork.join(); bjarneWork.join(); andreiWork.join(); andrewWork.join(); davidWork.join(); }