Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

beenotung
Copy link
Contributor

This change solves the race problem.
It makes sure the reference is made before the process dies.

This change solves the race problem.
It makes sure the reference is made before the process dies.
@whatyouhide
Copy link
Member

I realize the current code may be a bit hostile, but it's worth noting that you can most definitely monitor a dead process: you will just get the :DOWN message right when you monitor it and you'll get reason :noproc.

iex> pid = spawn fn -> :ok end
#PID<0.85.0>
iex> Process.monitor(pid) # "pid" is long dead here
#Reference<0.0.2.1188>
iex> flush()
{:DOWN, #Reference<0.0.2.1188>, :process, #PID<0.85.0>, :noproc}
:ok

Quoting the Erlang documentation:

Monitors are fired when the monitored process or port terminates, does not exist at the moment of creation, or if the connection to it is lost.

@josevalim
Copy link
Member

Yup, you should have no race but the proposed code is more readable, so thank you!

@josevalim josevalim merged commit b88405b into elixir-lang:master Feb 20, 2017
@josevalim
Copy link
Member

❤️ 💚 💙 💛 💜

vladdu pushed a commit to vladdu/elixir-lang.github.com that referenced this pull request Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants