userspace CONDITION-WAIT and interrupts
authorNikodemus Siivola <nikodemus@random-state.net>
Fri, 18 Nov 2011 18:05:38 +0000 (20:05 +0200)
committerNikodemus Siivola <nikodemus@random-state.net>
Fri, 18 Nov 2011 18:44:26 +0000 (20:44 +0200)
commitcb557a29b8b833b7753c2940e776eaa981633a9f
tree2f81f198bf9076c42106c1d8771e956db01d9db7
parentdcf7b5cbc859426d005b534f3fa273be5da0b64c
userspace CONDITION-WAIT and interrupts

  GC and signals cause WITHOUT-THREAD-WAITING-FOR to mark the thread as
  temporarily not waiting for anything, restoring the old status on unwind.

  This is fine for mutex deadlock detection, but now that the same slot is
  used for userspace condition variable wakeups we end up in trouble:

   T1: enqueue self on waitqueue, marked as waiting on it.

   T1: receives an interrupt and is marked as not waiting anymore while the
       interrupt is handled.

   T2: delivers a wakeup to the queue, sees T1 as not waiting anymore and
       drops it from the queue.

   T1: resumes waiting, but isn't on the queue, and never receives a wakeup.

       Extra Bonus:

       If T1 times out or unwinds for any reason, it sees itself as not having
       been woken up, and with interrupts disabled tries to unqueue itself
       from the queue -- ending up in an uninterruptible endless loop.

  The Fix:

    WITHOUT-THREAD-WAITING-FOR no longer restores the waiting-for information
    for waitqueues, effectively causing a bogus wakeup.
src/code/target-thread.lisp
src/code/thread.lisp