You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let res = self.state.compare_exchange(REGISTERING,WAITING,AcqRel,Acquire);// #1match res {Ok(_) => {}Err(actual) => {// This branch can only be reached if at least one// concurrent thread called `wake`. In this// case, `actual` **must** be `REGISTERING |// `WAKING`.debug_assert_eq!(actual,REGISTERING | WAKING);let waker = (*self.waker.get()).take().unwrap();// We need to return to WAITING state (clear our lock and// concurrent WAKING flag). This needs to acquire all// WAKING fetch_or releases and it needs to release our// update to self.waker, so we need a `swap` operation.self.state.swap(WAITING,AcqRel);// #2// ...}}
As shown in the comment, the Err(actual) branch can only be reached if there is a concurrent wake invoked during the REGISTERING, since the load part of compare_exchange is Acquire, and the writing part of self.state.fetch_or(WAKING, AcqRel) is Release, that is, #1 has synchronized with self.state.fetch_or, the reading part of #2 is unnecessary to be Acquire.
IIUC, self.state.swap(WAITING, AcqRel); can be changed to self.state.swap(WAITING, Release);
The text was updated successfully, but these errors were encountered:
As shown in the comment, the
Err(actual)
branch can only be reached if there is a concurrentwake
invoked during theREGISTERING
, since the load part ofcompare_exchange
isAcquire
, and the writing part ofself.state.fetch_or(WAKING, AcqRel)
isRelease
, that is,#1
has synchronized withself.state.fetch_or
, the reading part of#2
is unnecessary to beAcquire
.IIUC,
self.state.swap(WAITING, AcqRel);
can be changed toself.state.swap(WAITING, Release);
The text was updated successfully, but these errors were encountered: