Skip to content

atomicWait can steal a wakeup meant for an already-parked thread #1314

Description

@andreas-karlsson

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions