It abstracts from the implementation of a condition variable c ++

Taking the pseudocode below, if we avoid access to the condition / mutex variable from outside the Task Scheduler, which means that we can pass a predicate that is reading external indicators that are not protected by the waiting mutex. You are adding an empty lock scope before notifying that it is sufficient to synchronize everything correctly (that is, without missing notifications).

TaskScheduler class {

destruction of the vacuum (timeout, pred) {
signalDestroy ();
_wait (timeout, pred);
}

cancel notify () {
{
std :: lock_guard block (waitMutex);
}
waitCV.notify_all ();
}
private:
std :: mutex waitMutex;
std :: condition_variable waitCV;

void _wait (timeout, pred) {
std :: unique_lock block (waitMutex);
waitCV.wait_until (block,
time is over,
                          []() {return (internal state checks) || pred ();});
// the internal state modifications are made with blocked waitMutex but it is not the case for pred.
}

};
std :: atomic someFlag {false};
void thread1 () {
TaskScheduler :: destroy (INFINITY, [&]() {return someFlag;});
// take the case signalDestroy () does not really work, the only way to wait to abort is with someFlag = true;
}

void thread2 () {
// this is called while thread 1 is waiting to destroy
someFlag = true;
TaskScheduler :: notify ();
}