Can't understand Delay
's implementation in Async in depth
chapter
#6373
Unanswered
Chronostasys
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I'm reading tokio's documentation's
Async in-depth
chapter, and the implementation ofDelay
is confusing to me.The
Delay
's implementation inA few loose ends
is:I think there was a race condition when the waker changed.
As mentioned in the documentation:
Considering the following situation:
Delay
, the waker1 was stored, and the thread was spawned.Delay
'swhen
was just about to be reached when checkingInstant::now() >= self.when
, so it passed theif
check and continued. Before linelet mut waker = waker.lock().unwrap();
the thread spawned woke up and woke the waker1 stored on the first poll, then the executor thread changed the stored waker to the new wakerwaker2
.Pending
.The new waker was never signalled after the poll returned
Pending
!Is my understanding correct? If so, how to correct the
Delay
's implementation?Beta Was this translation helpful? Give feedback.
All reactions