by terminalcommand · 8y ago · 0 comments
Furthermore, in languages such as Erlang having an actor-based model, there are thousands and thousands of microthreads.
I think if you use lightweight threads (green threads, goroutines, etc.), the model does scale.
In Go, for example, I don't think OS threads are used at all, just processes. You can set GO_MAX_PROCS=1, for instance, and have all your goroutines running on a single process, effectively making it a single threaded system like Node. In that scenario, you're back at cooperative scheduling, because control will only transfer to another goroutine if you delegate to a runtime call or call os.Gosched() which is an explicit sleep + control transfer.
That's no thread - unless there is a real context switch (and cold caches) to pay for.