Skip to content

Tokio::sync::Notify::notify_one is wrong (should be fair) #288

Description

@sarsko

Per the tokio docs:

Notifies the first waiting task.

If a task is currently waiting, that task is notified. Otherwise, a permit is stored in this Notify value and the next call to [notified().await](https://docs.rs/tokio/latest/tokio/sync/struct.Notify.html#method.notified) will complete immediately consuming the permit made available by this call to notify_one().

At most one permit may be stored by Notify. Many sequential calls to notify_one will result in a single permit being stored. The next call to notified().await will complete immediately, but the one after that will wait.

We do the following currently:

// Choose a pending waiter at random
let index = state.rng.gen_range(0..pending.len());

Which is not the first waiting task.

Looking at Notify it seems like the whole module is due for a revisit

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