Guest User

Untitled

a guest
Feb 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. -module(sleeperl).
  2.  
  3. -compile(export_all).
  4.  
  5. testa() ->
  6. lists:map(fun(_) ->
  7. os:cmd("/bin/sleep 0.1")
  8. end, lists:seq(1, 50)).
  9.  
  10. testb() ->
  11. io:format("Receiver spawned at ~p~n", [now()]),
  12. Recv = spawn(fun() ->
  13. thisloop([])
  14. end),
  15. io:format("Spawn start at ~p~n", [now()]),
  16. lists:map(fun(_) ->
  17. spawn(fun() ->
  18. os:cmd("/bin/sleep 3"),
  19. Recv ! {done, self()}
  20. end)
  21. end, lists:seq(1, 5)),
  22. io:format("Spawn done at ~p~n", [now()]).
  23.  
  24. thisloop(Acc) ->
  25. NewAcc = receive
  26. X ->
  27. io:format("receiver got '~p' at ~p~n", [X, now()]),
  28. [X | Acc]
  29. end,
  30. thisloop(NewAcc).
Add Comment
Please, Sign In to add comment