What's the difference between notify_all() and notify_one() of std::condition_variable?

前端 未结 1 1890
不知归路
不知归路 2020-12-28 12:12

Currently, I am implementing a multi-thread project using std::thread in C++11. I use std::condition_variable to synchronize threads. In detail, on

相关标签:
1条回答
  • 2020-12-28 12:47

    If there are ten threads blocked on the condition variable, for example, notify_one() will unblock only one thread, while notify_all() will unblock them all. In your case, you'll want to use notify_one() so you don't wake up threads that don't have any work waiting for them.

    0 讨论(0)
提交回复
热议问题