Is There any Following C++ Blocking Condition Variable
I would like the have the following Blocking Condition Variable
- Once the blocking condition variable had been signaled, all threads will not wait on the particular condition variable
- The condition variable can be unsignaled anytime.
- Once condition variable had been unsignaled, all threads will be waiting on the variable
I look at http://www.boost.org/doc/libs/1_34_0/doc/html/boost/condition.html
However, it doesn't work in (1)
As if there are no thread waiting on the condition variable, the notify_one
/notify_all
called, will make the signal开发者_Python百科 lost
1) thread TA try wait on condition variable C
2) thread TB call `notify_all`
3) thread TA will continue execution
1) thread TB call `notify_all`
2) thread TA wait on condition variable C
3) thread TA will still continue waiting <-- How can I have condition variable C remains in
signaled state, and make no wait for thread TA
Your condition variable must be in combination with a boolean (wait) that has to be checked. Make wait false and notify all. So any thread that wasn't waiting should check the wait-variable and will continue.
Ofcourse, the threads will only wait again when they arrive at the condition variable code.
The solution is to have a manual reset Event as follow :
CreateEvent(0, TRUE, TRUE, 0);
Once it had been signaled through SetEvent, it will always be in signaled state.
精彩评论