4 ms·
I understand things best by comparing across different languages so don’t take this the wrong way but I wonder if you can help me understand: If say I start a g
by dullcrisp 2y ago
I understand things best by comparing across different languages so don’t take this the wrong way but I wonder if you can help me understand: If say I start a goroutine in Go and give it a channel to use as a mailbox, concurrency in Go is cooperative but it’ll automatically use OS threads and yield whenever it reads from the channel. Does Erlang/OTP do something different? If so what does it do and what are the advantages? Or is it more that the library and ecosystem are built around this model?
- throwawaymaths 2y agoI 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.