Skip to content

Instantly share code, notes, and snippets.

@mattyw
Created June 17, 2013 21:13
Show Gist options
  • Save mattyw/5800508 to your computer and use it in GitHub Desktop.
Save mattyw/5800508 to your computer and use it in GitHub Desktop.
When I run this code I get: =ERROR REPORT==== 17-Jun-2013::22:09:20 === Too many processes ** (SystemLimitError) a system limit has been reached :erlang.spawn(Main, :thread, [#PID<0.2.0>])
import :timer, only: [sleep: 1]
defmodule Main do
@num 1000000
def thread(pid) do
:timer.sleep(10000)
pid <- {:result, 1}
end
def collector(x) when x == @num do
:done
end
def collector(x) do
receive do
{:result, n} ->
IO.puts inspect n + x
collector((x + n))
end
end
def spawner(x) when x == @num do
:done
end
def spawner(x) do
spawn(__MODULE__, :thread, [self])
spawner(x + 1)
end
def main() do
spawner(0)
collector(0)
end
end
Main.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment