Issue #3212 has been updated by Sylvain Joyeux.


Yusuke's answer and mine apply to #3213, not to this bug.

This bug is a different problem. In Yusuke's example, the following happens 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 "real" wakeup happens, @waiters still has 'a' in it and the next call to #signal or #broadcast will wake 'a' up even if 'a' does not wait on the condition variable.

IMO, #wait should ensure that the current thread has been removed from the waiter's list:

  def wait(mutex)
    t = Thread.current
    @waiters_mutex.synchronize do
      @waiters.push(t)
    end
    mutex.sleep
  rescue
    @waiters_mutex.synchronize do
      @waiters.delete(t)
    end
  end

----------------------------------------
http://redmine.ruby-lang.org/issues/show/3212

----------------------------------------
http://redmine.ruby-lang.org