Skip to content

Possible race condition on Windows platform causing task to never wake #44

@Andrepuel

Description

@Andrepuel

Context:

if !self.resync.swap(false, Ordering::Relaxed) {

The potential scenario with two threads:

  1. Thread A runs line 99, resync AtomicBool returns false
    if !self.resync.swap(false, Ordering::Relaxed) {
  2. Thread B, the win32 notifier, runs line 61, sets resync to true
    resync.store(true, Ordering::Relaxed);
  3. Thread B, runs line 62, there is no watcher on the AtomicWaker yet
    waker.wake();
  4. Thread A run lines 100, stores the Waker
    self.waker.register(cx.waker());
  5. Thread A returns Pending
    return Poll::Pending;

The task running on Thread A will be pending forever, because resync is true while the call to waker.wake() was done before the Waker itself was registered.

Registering the Waker before loading resync would fix this issue, with the added side of effect of possible spurious wakes. However, spurious wakes should always be expected when dealing with Future. Another approach, would be to have both resync and waker inside a mutex, then we can read resync and set the waker on the same critical area.

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