ERLANG wait () and lock

Does the following function block have on its working core?

The big answer will detail the inner workings of erlang and / or the processor.

wait(Sec) -> receive after (1000 * Sec) -> ok end. 
+6
source share
3 answers

The process that executes this code is blocked; the scheduler that starts this process does not currently block. You sent a code equal to profitability, but with a timeout.

The Erlang VM scheduler for this kernel will continue to execute other processes until this timeout is lit, and this process is scheduled to run again.

+7
source

Short answer: this will only block the current (light) process and will not block all virtual machines. For more information, you should read about the erlang scheduler. A good description is taken from the book "Consistent Programming" by Francesco Cesarini and Simon Thompson.

... chik ... When a process is sent, it is assigned a series of abbreviations † it is allowed to perform, a number that decreases for each operation performed. As soon as the process is included in the offer of receipt where none of the messages matches or the number of its reductions does not reach zero, it is unloaded. Until the BIFs are executed, this strategy leads to a fair (but not equal) distribution of execution between the processes .... chik ...

+2
source

There is no Erlang-specific, rather classic problem: timeouts can occur only when the system clock is interrupted. The same answer as above: this process is blocked, waiting for the interruption of the clock, everything else works fine.

There is another discussion of the actual time during which the process will wait, which is not accurate precisely because it depends on the time period (and depends on the system), but on a different topic.

+1
source

Source: https://habr.com/ru/post/906725/


All Articles