-
Hello, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The lock doesn't protect the |
Beta Was this translation helpful? Give feedback.
-
Hello, |
Beta Was this translation helpful? Give feedback.
-
The lock doesn't protect the |
Beta Was this translation helpful? Give feedback.
The lock doesn't protect the
Task
itself (as no one calls into it while within the lock anyway). Rather, the lock is to guard the state of our ownAsyncManualResetEvent
class itself. Consider where else the lock is taken in the class, around where that field is manipulated. Generally speaking, it could be that if another method is holding the lock, that the field's value might not be something we'd want to return from the WaitAsync method.Another (very likely) reason is that we use a lock to avoid doing the more advanced memory barriers. Without a kind of memory barrier, we might return a stale value from the field long after it's been changed by a call to Set/Reset due to CPU core memor…