If I create a file loop.exs
:
Enum.each(1..40000, fn (n) -> spawn fn -> IO.puts(n) end end)
And run it, counting the lines of output:
elixir loop.exs | wc -l
And on subsequent runs, I may see the expected 40000
lines, but I might see less. In my tests, I've seen 39752
, 39934
, 39673
, etc. This suggests to me that certain processes aren't getting to call IO.puts
, so what is happening to them, why aren't I warned they've gone missing, and what am I doing wrong that is making this happen?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…