Created
March 10, 2016 18:10
-
-
Save anonymous/94ace7cd94fd5930f3e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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