File tree 1 file changed +20
-0
lines changed
library/std/src/thread/parker
1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,26 @@ pub struct Parker {
11
11
state : AtomicI32 ,
12
12
}
13
13
14
+ // Notes about memory ordering:
15
+ //
16
+ // Memory ordering is only relevant for the relative ordering of operations
17
+ // between different variables. Even Ordering::Relaxed guarantees a
18
+ // monotonic/consistent order when looking at just a single atomic variable.
19
+ //
20
+ // So, since this parker is just a single atomic variable, we only need to look
21
+ // at the ordering guarantees we need to provide to the 'outside world'.
22
+ //
23
+ // The only memory ordering guarantee that parking and unparking provide, is
24
+ // that things which happened before unpark() are visible on the thread
25
+ // returning from park() afterwards. Otherwise, it was effectively unparked
26
+ // before unpark() was called while still consuming the 'token'.
27
+ //
28
+ // In other words, unpark() needs to synchronize with the part of park() that
29
+ // consumes the token and returns.
30
+ //
31
+ // This is done with a release-acquire synchronization, by using
32
+ // Ordering::Release when writing NOTIFIED (the 'token') in unpark(), and using
33
+ // Ordering::Acquire when checking for this state in park().
14
34
impl Parker {
15
35
#[ inline]
16
36
pub const fn new ( ) -> Self {
You can’t perform that action at this time.
0 commit comments