Guest User

Untitled

a guest
Aug 17th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 0.67 KB | None | 0 0
  1. -module(ex42).
  2. -export([start/3,start_proc/2]).
  3.  
  4. start(N,M,Message) ->
  5.     start_proc(self(),N),
  6. receive
  7.     {C}-> C! {mes,M,Message,self()}
  8. end.
  9.  
  10. start_proc(Pid,1) ->
  11. io:format("Element ~w started~n",[1]),
  12. io:format("My PID=~w",[self()]),
  13. Pid ! {self()},
  14. receive
  15.     {mes,M,Message,P} ->
  16.     io:format("Message = ~w received from P=~w",[Message],[P]);
  17.     quit -> true
  18. end;
  19.    
  20. start_proc(Pid,N) ->
  21. NPid = spawn(?MODULE,start_proc,[Pid,N-1]),
  22. io:format("Element ~w started~n",[N]),
  23. io:format("My PID=~w",[self()]),
  24. Pid ! self(),
  25. receive
  26.     {mes,M,Message,P} ->
  27.     io:format("Message = ~w received from P=~w",[Message],[P]),
  28.     NPid! {mes,M,Message,P};
  29.     quit -> true
  30. end.
Add Comment
Please, Sign In to add comment