Hi,

2010/5/3 Sylvain Joyeux <redmine / ruby-lang.org>:
> Yusuke's answer and mine apply to #3213, not to this bug.
>
> This bug is a different problem. In Yusuke's example, the following happe=
ns if 'a' gets a spurious wakeup:
>
> The CV's internal @waiters array still contains 'a'. Then, the next call =
to #wait() will add it again (@waiters contains 'a' two times). When a "rea=
l" wakeup happens, @waiters still has 'a' in it and the next call to #signa=
l or #broadcast will wake 'a' up even if 'a' does not wait on the condition=
 variable.


No, 'a' *does* wait on the CV as long as you are using CV#wait
correctly.


1) Thread 'a' gets a spurious wakeup
2) Thread 'a' evaluates your condition (predicate) and figures out
   it false (because the CV has not been signaled formally by 'b')
3) Thread 'a' waits the CV again

4) Thread 'b' call CV#signal which makes wake 'a' up


#4 cannot occur between #1 and #3 because the corresponding mutex
should be locked when calling CV#signal.


If you have any concrete problem, please elaborate it.

--=20
Yusuke Endoh <mame / tsg.ne.jp>