2 ms·
The thing this post doesn't distinguish is a 'thread' vs a fiber/coroutine/goroutine/etc. For example if you write something in Go without using async and spaw
by karmakaze 3y ago
The thing this post doesn't distinguish is a 'thread' vs a fiber/coroutine/goroutine/etc.
For example if you write something in Go without using async and spawning a bunch of goroutines, they could execute on one thread (if you set GOMAXPROCS=1) or many (the default is the number of cores/hyperthreads of your processors). On virtually any library function call, the goroutine could yield and switch to executing a different goroutine. This is all transparent and IMO preferable to write and read than explicitly passing callbacks, or having the compiler rewrite any await as 'rest of program' passed as a callback.
For small numbers of goroutines, actual OS threads could instead be used effectively, but as that number gets large, there's overhead of thread context switches and scheduler work that becomes significant.