Thanks to the book of the Doctor Scott Meyers, page 263, I recently discovered condition_variable
, so I had to search about it on cppreference to study it more.
https://en.cppreference.com/w/cpp/thread/condition_variable
I have several questions on it, because I think on it since several days, and I still did not understand.
My questions are about this piece of code :
// Manual unlocking is done before notifying, to avoid waking up
// the waiting thread only to block again (see notify_one for details)
lk.unlock();
cv.notify_one();
1) I do not understand what the author of the cppreference means by that comment and by "the waiting thread, only to block again" because I don't know even how to translate it, and
2) Which threads it denotes exactly, and why in particular.
3) Does it denote the thread_worker or the main thread (parent) ?
4) What they chose to do that ?
And what does it change if the authors notify first and then manually unlock ?