3 ms·
Async/await provides a mechanism for explicit context switching between threads. This is useful when you might need to run code on specific native threads or o
by jayd16 6y ago
Async/await provides a mechanism for explicit context switching between threads. This is useful when you might need to run code on specific native threads or other native tasks outside the runtime.
It seems like it would be much harder or impossible in languages that work to hide these details. How do you go from implicit blocking to explicit native thread usage?
At least Loom seems to be keeping native threads so Java code can simply fall back to that, I guess.
- pjmlp 6y agoYou can also use native threads in Go, by locking the current goroutine thread.
- yxhuvud 6y agoOne way to solve it is to introduce a concept like a nursery (a la structured concurrency) and when setting it up you instruct it to create a new thread that is only used for those particular tasks. This of course requires a scheduler that needs to handle hierarchical control of execution rather than having an unformed mass of tasks, but nurseries provide other benefits as well.