[erlang-questions] How does Erlang schedule process?
Richard A. O'Keefe
ok@REDACTED
Wed Mar 9 00:45:11 CET 2016
On 9/03/16 6:12 am, Jung Kim wrote:
> I am very new to Erlang, and just read that Erlang style process is
> done with something similar to coroutine + preemptive scheduling[1].
That could be said of ANY programming language that offers threads,
including
C, C++, Java, &c. It's really not very helpful, because more people
these days
know about threads than know about coroutines. In fact when I *want*
coroutines in most programming languages these days, I use threads instead.
> So I am interested to know how Erlang schedule process without the
> user inserting code like coroutine.yield() in the function created.
Do you understand how UNIX schedules processes without the user calling
the POSIX sched_yield() function? In effect, the operating system uses
timer interrupts to forcibly insert sched_yield() calls, or switches to
doing
something else whenever a (UNIX) process needs to wait.
Those are the two basic techniques used by any process/thread
implementation:
if a process/thread starts an operation and needs to wait for
completion, that
process/thread is put into a wait state and something that's ready to run is
executed in its place, OR a 'yield' is inserted when a timer goes off or
an event
counter (like Erlang's "reduction count") reaches a limit.
> Is there any document detail about this (I find some discussion like
> [2] but that doesn't give me a clear blueprint)? Or which part of
> source code should I look into?
How much detail do you need? Do you understand how this kind of thing works
in UNIX or Windows? If you don't, try reading a good book about operating
systems first.
More information about the erlang-questions
mailing list