News for hackers. Stuff that matters.
Re:Tokio Console by javajosh on Friday December 17, 2021 @08:53PM (#29600741)
I read your link earlier today, and have been thinking about it; I particularly like the pedagogy of rebuilding it "in the small" with your MiniTokio example.

I don't know Rust. If I had to guess, this means that you've reused Rust's threads for tasks, such that they may not be done computing when a resource is available? In any event, I want to circle back to the OP, and note that runtime visualizations like this are awesome, and conversations like this is why. I personally don't think anyone spends enough time dwelling in their runtime(s), and certainly no async runtime has good visualizations, so its pretty cool to me that tokio-console is taking the lead here. I've been bullish on Rust for 5 years; maybe it's time to try it out for reals.

Re:Tokio Console by gpm on Friday December 17, 2021 @11:16PM (#29601591)
The purpose of async is mostly to avoid OS threads, and rust decided not to go down the route of implementing user space threads.

Instead, for async, rust implemented the ability to basically encode a functions stack frame and instruction pointer into a "normal" (but opaque) struct. What an async runtime like tokio does is (through a few levels of useful indirection that I won't talk about) store a list of these structs, and decide when it's a good idea to "call" one of them. When called, the structs either return a final value, or return a value saying "call me again later", in which case the runtime presumably puts it back into it's list of structs and calls it again sometime later.

Figuring out when to call it is left up to the runtime, but the useful ones will do things like record what operation it's waiting for and call it when that operation is ready.

Re:Tokio Console by lilyball on Saturday December 18, 2021 @02:57AM (#29602674)
> rust decided not to go down the route of implementing user space threads

Rust had (optional) user-space threads a long time ago, but that was removed in the pre-1.0 days as it added a lot of complexity and had some unavoidable performance loss even when opting for native threads (it forced dynamic dispatch on anything related to threading or I/O). There was a lot of discussion here but eventually it was declared that the OS thread scheduler was in fact perfectly capable of handling large numbers of threads and that virtual memory mapping meant the stack space allocation for each thread wasn’t a big deal and so green threads were removed.

Re:Tokio Console by lenkite on Saturday December 18, 2021 @03:33AM (#29602879)
These feel like co-routines.
Re:Tokio Console by gpm on Saturday December 18, 2021 @09:01AM (#29604537)
Yep, basically equivalent to stackless coroutines.