I am looking for information on how Erlang internally handle the receive call.
report(Count) ->
receive
X -> io:format("Received #~p: ~p~n", [Count, X]),
end.
Is receive executed on same thread than other functions? Do each process is responsible to call his own receive? Do Erlang use a "god" process that call all the receive?
After a receive statement, the process first checks if there in the mail box any message which matches one of the receive clauses. If not it enters in wait state (interaction with the scheduler, but I have no detail). Then the scheduler will reschedule the process only if a new message is put in the mail box, or if the time out (after clause) occurs.