4 ms·
I believe go yields after every function exit. Erlang does the same, but there are no loops (you must use tailcall) so you can't lock up the CPU with a while(t
by throwawaymaths 2y ago
I believe go yields after every function exit. Erlang does the same, but there are no loops (you must use tailcall) so you can't lock up the CPU with a while(true).
- samatman 2y agoThat used to be true, but no longer, goroutines are truly preëmptive, in 10ms time slices.
- throwawaymaths 2y agoThanks!
- Jtsummers 2y agoErlang gives a reductions budget to processes. After a certain number of reductions, or if a process hits a yield point (like waiting to receive a message), the process will yield allowing another process to run. Go uses preemption now (since 1.14), but it didn't always. It used to be that you could use a busy loop and that goroutine would never yield. Yield points include things like function entries, syscalls, and a few other points.