File tree 1 file changed +6
-11
lines changed
library/std/src/sys_common/thread_parking
1 file changed +6
-11
lines changed Original file line number Diff line number Diff line change @@ -56,18 +56,14 @@ impl Parker {
56
56
self . init_tid ( ) ;
57
57
58
58
// Changes NOTIFIED to EMPTY and EMPTY to PARKED.
59
- let mut state = self . state . fetch_sub ( 1 , Acquire ) . wrapping_sub ( 1 ) ;
60
- if state == PARKED {
59
+ let state = self . state . fetch_sub ( 1 , Acquire ) ;
60
+ if state == EMPTY {
61
61
// Loop to guard against spurious wakeups.
62
- while state == PARKED {
62
+ // The state must be reset with acquire ordering to ensure that all
63
+ // calls to `unpark` synchronize with this thread.
64
+ while self . state . compare_exchange ( NOTIFIED , EMPTY , Acquire , Relaxed ) . is_err ( ) {
63
65
park ( self . state . as_ptr ( ) . addr ( ) ) ;
64
- state = self . state . load ( Acquire ) ;
65
66
}
66
-
67
- // Since the state change has already been observed with acquire
68
- // ordering, the state can be reset with a relaxed store instead
69
- // of a swap.
70
- self . state . store ( EMPTY , Relaxed ) ;
71
67
}
72
68
}
73
69
@@ -78,8 +74,7 @@ impl Parker {
78
74
if state == PARKED {
79
75
park_timeout ( dur, self . state . as_ptr ( ) . addr ( ) ) ;
80
76
// Swap to ensure that we observe all state changes with acquire
81
- // ordering, even if the state has been changed after the timeout
82
- // occurred.
77
+ // ordering.
83
78
self . state . swap ( EMPTY , Acquire ) ;
84
79
}
85
80
}
You can’t perform that action at this time.
0 commit comments