@@ -63,7 +63,7 @@ thread_local! {
63
63
impl ArcWake for ThreadNotify {
64
64
fn wake_by_ref ( arc_self : & Arc < Self > ) {
65
65
// Make sure the wakeup is remembered until the next `park()`.
66
- let unparked = arc_self. unparked . swap ( true , Ordering :: Relaxed ) ;
66
+ let unparked = arc_self. unparked . swap ( true , Ordering :: Release ) ;
67
67
if !unparked {
68
68
// If the thread has not been unparked yet, it must be done
69
69
// now. If it was actually parked, it will run again,
@@ -90,17 +90,13 @@ fn run_executor<T, F: FnMut(&mut Context<'_>) -> Poll<T>>(mut f: F) -> T {
90
90
if let Poll :: Ready ( t) = f ( & mut cx) {
91
91
return t;
92
92
}
93
- // Consume the wakeup that occurred while executing `f`, if any.
94
- let unparked = thread_notify . unparked . swap ( false , Ordering :: Acquire ) ;
95
- if ! unparked {
93
+
94
+ // Wait for a wakeup.
95
+ while !thread_notify . unparked . swap ( false , Ordering :: Acquire ) {
96
96
// No wakeup occurred. It may occur now, right before parking,
97
97
// but in that case the token made available by `unpark()`
98
98
// is guaranteed to still be available and `park()` is a no-op.
99
99
thread:: park ( ) ;
100
- // When the thread is unparked, `unparked` will have been set
101
- // and needs to be unset before the next call to `f` to avoid
102
- // a redundant loop iteration.
103
- thread_notify. unparked . store ( false , Ordering :: Release ) ;
104
100
}
105
101
}
106
102
} )
0 commit comments