Trying to understand how FuturesUnordered works. Getting tripped up with how the ready_to_run_queue interacts with linked list. Specifically, confused by pending_next_all, spin_next_all, link, and unlink. Does anyone have a good reference as to how this works? Specific questions include:
The docs mention under heavy thread contention, a compare-exchange loop could become costly. What does thread contention mean here?
How does using stub resolve this? Confused as to how using pending_next_all allows next_all as needed for iterator. When will there be a case where head_all -> stub -> next?
More generally, would love an explanation about how ready_to_run_queue works with head_all, next_all pointers and stub. Particularly for the impl Stream block
Hmm. Usingjoin_all before, and have of course read bunch of poll implementations, but, perhaps clouded by recent experience with FuturesUnordered.
Edit: reading through poll implementation for JoinAll. Basic understanding is that for each ElemState, call poll. If any NotReady, return NotReady otherwise return Ready(result). Feel free to ask other questions to gauge understanding make it easier to write an answer.
Hmm. Usingjoin_all before, and have of course read bunch of poll implementations, but, perhaps clouded by recent experience with FuturesUnordered.
Edit: reading through poll implementation for JoinAll. Basic understanding is that for each ElemState, call poll. If any NotReady, return NotReady otherwise return Ready(result). Feel free to ask other questions to gauge understanding make it easier to write an answer.
Is there a better place to ask this question. Happy redirect this question to a place where it may be more appropriate, but didn't see anything in the repo..
I haven't really had the time to check out the source again to remind myself of how it works. You could open an issue on the crate, or ask in e.g. Tokio's discord. That would increase the pool of people who can answer who sees it.
I don't think futures has its own discord, but you are certainly welcome to ask them on Tokio's discord, as they are tools relevant to people using Tokio. You can also ask questions here.
If you search the history of #tokio-dev on the Tokio discord, I'm pretty sure you will find several discussions, because we have had some talk about adding it to Tokio proper.
FuturesUnordered, unlike join_all, doesn't poll ALL tasks per poll. Instead, FuturesUnordered polls each task individually as the waker gets called for the specific task.
This link provided does not help much in understanding the linked list, ready_to_run_queue, and spinning. The Tokio discussion post also did not get any responses. Next step is to try discord.