views:

103

answers:

2

I would like the have the following Blocking Condition Variable

  1. Once the blocking condition variable had been signaled, all threads will not wait on the particular condition variable
  2. The condition variable can be unsignaled anytime.
  3. 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 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
+1  A: 

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.

stefaanv
A: 

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.

Yan Cheng CHEOK
If you are working in Windows.
tony