|
|
|
|
|
by Jtsummers
3022 days ago
|
|
receive is a blocking action in erlang so something like: loop(State) ->
receive
msg -> loop(State)
end.
Will block waiting for `msg` to show up. So if you have two processes that are interacting with eachother and aren't careful in constructing their communication you could end up with something (contrived): loop(Pid) ->
receive
msg -> Pid ! msg
end,
loop(Pid).
If you have two processes A and B that end up in this same loop but referencing each other, they'd deadlock. Substituting A and B for Pid you'd end up with something like: loop(B) -> % Process A
receive
msg -> B ! msg
end,
loop(B).
loop(A) -> % Process B
receive
msg -> A ! msg
end,
loop(A).
Both waiting for `msg` but never sending it to their partner process. |
|
but then you can 'deadlock' for a single pid as well right ? where you wait for a message which no one is sending...