Search code examples
erlangwait

ERLANG wait() and blocking


Does the following function block on its running core?

wait(Sec) -> 
   receive
   after (1000 * Sec) -> ok
end.

A great answer will detail the internal working of Erlang and/or the CPU.


Solution

  • The process which executes that code will block, the scheduler which runs that process currently will not block. The code you posted is equal to a yield, but with a timeout.

    The Erlang VM scheduler for that core will continue to execute other processes until that timeout fires and that process will be scheduled for execution again.