Skip to content
Discussion options

You must be logged in to vote

We have thought of this of course :)

Tokio uses a counter for the number of readiness events to avoid this race condition. To perform a read, it does these things:

  1. Read the value of the counter.
  2. Perform the read.
  3. If the read returns EWOULDBLOCK, store the value of the counter from before the read.

When you call .await on readable(), it will wait until the readiness counter becomes larger than the value stored in step 3. If it's already larger, then it returns immediately. This means that any readiness event that happened after step 1 (so including events during step 2), will be enough for readable().await to return immediately.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jw4js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants