3 ms·
That is, a bit like TFA, a tad too high-level for what I was hoping to find here. What's immensely mentally blocking me is how such high-level, admittedly eleg
by diarrhea 3y ago
That is, a bit like TFA, a tad too high-level for what I was hoping to find here.
What's immensely mentally blocking me is how such high-level, admittedly elegant solutions translate down. Async code writes naturally in JS/Node.js, great; but it's imperative code on the lower levels, assembly even. The article mainly defers to libuv. But how does it work?
Add to that the different concurrency models. Some runtimes are async and multithreaded (.NET, don't know about JVM, ...), some are single-threaded async (Python, I guess Node.js as well, ...). Some are native code async, which can be either single- or multithreaded (Rust).
I'm aware of coroutines and how they do cooperative multitasking, green threads, native threads, ...
A large, complex landscape that I have been trying to grok and fit into a unified mental model, but I am slowly losing hope that's even possible. Things seem too heterogeneous.
If anyone knows a good resource (preferably book) on this topic, I'd love to hear about it.
- brmgb 3y ago> But how does it work? There clearly is something doing the scheduling and dispatching somewhere in the stack. There will most likely be queues involved and data structures linking receivers and emitters if you are using events. If you use system threads, they might actually be multiple schedulers involved (the OS one and the runtime one). My advice is to pick up a system book about designing OS which will have a section about scheduling and work from there. Runtime schedulers are not that different.
- milesvp 3y agoso at a fundamental level, there’s really nothing other time slicing and interrupts. anything a single cpu does that looks like it’s doing 2 things at once, usually there’s some loop somewhere that is moving data in and out of registers to allow 2 pieces of code to run interleaved. usually it’s doing this many times a second. if the os doesn’t do this, the code running on the os can. then there’s interrupts. if there is no threading loop, you can still register interrupts. this is a fundamental concept in cpu design. every cpu has some way of interrupting the current task and run some function. so you can register an interrupt handler for certain types of interrupts, and that code then is run instead of whatever code is running then when the interrupt is handled it does back to the place it was. It looks like you have non imperative code because 2 things happened close enough to look simultaneous, but its still sliced.