atomicNotify should only be able to wake threads that are already parked in atomicWait. Because of how the pending-wakeup permit is tracked, a thread that calls atomicWait after a notify has already fired can consume that permit and return immediately — without ever actually waiting — even though it wasn't parked when the notify happened. This steals the wakeup from the thread that was legitimately parked, which then has no way to know it needs to re-wait and can sleep forever.
Discovered via deadlocks in an otherwise-correct rw-lock implementation built on top of atomicWait/atomicNotify.
atomicNotifyshould only be able to wake threads that are already parked inatomicWait. Because of how the pending-wakeup permit is tracked, a thread that calls atomicWait after a notify has already fired can consume that permit and return immediately — without ever actually waiting — even though it wasn't parked when the notify happened. This steals the wakeup from the thread that was legitimately parked, which then has no way to know it needs to re-wait and can sleep forever.Discovered via deadlocks in an otherwise-correct rw-lock implementation built on top of atomicWait/atomicNotify.