Skip to content

Instantly share code, notes, and snippets.

/lotsa.erl
Created Mar 10, 2016

Embed
What would you like to do?
-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
You can’t perform that action at this time.