Erlang is a well-known programming language that is famous (among other things) for it's lightweight threading. Erlang is usually implemented with the BEAM machine. The description (H'97) of the Erlang BEAM machine says
To guarantee a fair scheduling a process is suspended after a fixed number of reductions and then the first process from the queue is resumed.
I'm interested in this notion of reduction. According to (H'97) only the following BEAM commands count as a reduction:
- C/CO/ResC: calls local/resident Erlang function
- CL: Discard the current stack frame. Call a local Erlang function.
- CEx/TrCEx: Call an external Erlang function (traced or otherwise).
- CExL/TrCExL: Discard the current stack frame and call an external Erlang fuction (traced or otherwise).
- M_C_r: Load the argument register x(0). Call a resident Erlang function.
- M_CL_r: Load the argument register x(0). Discard the current stack frame. Call a local Erlang function.
All of those involve a function call. In contrast, calls to C-functions (e.g. TrC/TrCO) and calls to built-in functions (e.g. called by Bif_0_) don't count as reductions.
Questions. After this preamble, here is what I would like to know.
- Why are reductions used for scheduling between threads, and not time-slices?
- Why do only the above commands advance the reduction counter?
- The description in (H'97) is a bit dated, how does contemporary Erlang handle scheduling?
(H'97) B. Hausman, The Erlang BEAM Virtual Machine Specification.