Skip to content

Does TcpStream split need to take a mutable reference? #3657

Answered by Darksonn
bjadamson asked this question in Ideas
Discussion options

You must be logged in to vote

There is a reason behind it taking a mutable reference. Consider what happens if you try to read simultaneously from two references to the same TcpStream. Ultimately these two reads will result in both tasks calling poll_read on the same TcpStream, but all poll methods behave like the following (taken from Future::poll):

Note that on multiple calls to poll, only the Waker from the Context passed to the most recent call should be scheduled to receive a wakeup.

This poses a problem. It is not possible for both calls to poll_read to be the most recent caller simultaneously, and this means that one of them wont be woken up, which essentially means that its call to read will hang forever. Mu…

Replies: 1 comment

Comment options

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