Created
August 26, 2008 18:16
-
-
Save ngerakines/7311 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
Eshell V5.6.2 (abort with ^G) | |
1> c(sleeperl). | |
{ok,sleeperl} | |
2> sleeperl:testb(). | |
Receiver spawned at {1219,775147,552727} | |
Spawn start at {1219,775147,552864} | |
Spawn done at {1219,775147,553079} | |
ok | |
3> | |
receiver got '{done,<0.38.0>}' at {1219,775150,571689} | |
receiver got '{done,<0.40.0>}' at {1219,775150,573514} | |
receiver got '{done,<0.39.0>}' at {1219,775150,574316} | |
receiver got '{done,<0.41.0>}' at {1219,775150,583109} | |
receiver got '{done,<0.42.0>}' at {1219,775150,584700} | |
3> |
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(sleeperl). | |
-compile(export_all). | |
testa() -> | |
lists:map(fun(_) -> | |
os:cmd("/bin/sleep 0.1") | |
end, lists:seq(1, 50)). | |
testb() -> | |
io:format("Receiver spawned at ~p~n", [now()]), | |
Recv = spawn(fun() -> | |
thisloop([]) | |
end), | |
io:format("Spawn start at ~p~n", [now()]), | |
lists:map(fun(_) -> | |
spawn(fun() -> | |
os:cmd("/bin/sleep 3"), | |
Recv ! {done, self()} | |
end) | |
end, lists:seq(1, 5)), | |
io:format("Spawn done at ~p~n", [now()]). | |
thisloop(Acc) -> | |
NewAcc = receive | |
X -> | |
io:format("receiver got '~p' at ~p~n", [X, now()]), | |
[X | Acc] | |
end, | |
thisloop(NewAcc). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment