Skip to content

Instantly share code, notes, and snippets.

Created March 10, 2016 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/94ace7cd94fd5930f3e4 to your computer and use it in GitHub Desktop.
Save anonymous/94ace7cd94fd5930f3e4 to your computer and use it in GitHub Desktop.
-module(lotsa).
% example usage:
% lotsa:run(fun lotsa:sample_fun/1, 100000).
-export([run/2, sample_fun/1]).
run(Fun, N) ->
spawn_processes(Fun, N, self()),
await_returns(N),
done.
spawn_processes(_Fun, 0, _MasterPid) -> ok;
spawn_processes(Fun, N, MasterPid) ->
spawn(fun () -> Fun(MasterPid) end),
spawn_processes(Fun, N-1, MasterPid).
await_returns(0) -> done;
await_returns(N) ->
receive
done -> ok
end,
await_returns(N-1).
sample_fun(MasterPid) ->
do_work,
MasterPid ! done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment