mercredi 18 novembre 2020

Calling std::condition_variable::notify_one() multiple times before std::condition_variable::wait() is called

I am struggling to understand the way std::condition_variable is used. Let's say I have Producer and consumer thread and both are operating on same condition_variable. Producer fills the data to process very fast and calls std::condition_variable::notify_one() every time a data is pushed to container. So let's say Producer pushed 10 items and called notify_one() 10 times even before consumer can process data that was added first. Now producer thread exits so it will not call nootify_one() anymore so what will happen to consumer thread who is waiting on condition_variable? Will previous 9 calls to notify_one() will be queued and consumer will be unblocked 9 times more?

Aucun commentaire:

Enregistrer un commentaire