Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -module(ex42).
- -export([start/3,start_proc/2]).
- start(N,M,Message) ->
- start_proc(self(),N),
- receive
- {C}-> C! {mes,M,Message,self()}
- end.
- start_proc(Pid,1) ->
- io:format("Element ~w started~n",[1]),
- io:format("My PID=~w",[self()]),
- Pid ! {self()},
- receive
- {mes,M,Message,P} ->
- io:format("Message = ~w received from P=~w",[Message],[P]);
- quit -> true
- end;
- start_proc(Pid,N) ->
- NPid = spawn(?MODULE,start_proc,[Pid,N-1]),
- io:format("Element ~w started~n",[N]),
- io:format("My PID=~w",[self()]),
- Pid ! self(),
- receive
- {mes,M,Message,P} ->
- io:format("Message = ~w received from P=~w",[Message],[P]),
- NPid! {mes,M,Message,P};
- quit -> true
- end.
Add Comment
Please, Sign In to add comment