1.0.37.34: Fix lost wakeup bug between CONDITION-WAIT and CONDITION-NOTIFY.
authorTobias C. Rittweiler <trittweiler@users.sourceforge.net>
Sat, 3 Apr 2010 18:06:37 +0000 (18:06 +0000)
committerTobias C. Rittweiler <trittweiler@users.sourceforge.net>
Sat, 3 Apr 2010 18:06:37 +0000 (18:06 +0000)
commit93ed7777d86296768a1e98acd5b08873c5aec8e4
tree7593abc086fa9f0123b094e7d976227278151411
parent883474646eb02d2fc0de5dcf4c63cf7ff794b2eb
1.0.37.34: Fix lost wakeup bug between CONDITION-WAIT and CONDITION-NOTIFY.

(Patch and write up below are actually due to Nikodemus.)

Use the waitqueue object as the data item in CONDITION-NOTIFY, and the
thread in CONDITION-WAIT.

It doesn't matter if multiple notifies use the same object -- single
thread notifying multiple times has the same meaning as multiple
threads sending one notification each, but multiple waiters must use
different objects as per following scenario:

   1) Thread A calls CONDITION-WAIT on a condition variable CVAR.

      Thread A sets CVAR's waitqueue-data to token A.

      Thread A is preempted after the (RELEASE-MUTEX), before the
      FUTEX-WAIT.

   2) Thread B is run. Thread B invokes CONDITION-NOTIFY.

      Thread B sets CVAR's waitqueue-data to a token B.

      Thread B invokes FUTEX-WAKE which is NO-OP because no thread is
      yet waiting on the futex.

   3) Thread C is run. Thread C invokes CONDITION-WAIT.

      Thread C sets CVAR's waitqueue-data to token C.

   4) Thread A is finally run again. The call to FUTEX-WAIT compares
      CVAR's waitqueue-data with token A. If token A == token C, the
      wakeup is lost.

Similarly, if step 3 does not happen, and token A == token B, the
wakeup is lost.

Furthermore, consider if thread A == thread B, and step 3 does not
happen.  (This can occur due to an interrupt.) Hence CONDITION-NOTIFY
cannot use the thread object as the token.
NEWS
src/code/target-thread.lisp
version.lisp-expr