fork download
  1. -module(prog).
  2. -export([main/0]).
  3.  
  4. main() ->
  5. Pid = spawn(fun() -> loop(0) end),
  6. procidurka(Pid, update_n),
  7. R1 = tipa_function(Pid, get_n),
  8. io:format("after procidurka call tipa_function returned: ~p~n",[R1]),
  9. procidurka(Pid, update_n),
  10. R2 = tipa_function(Pid, get_n),
  11. io:format("after procidurka call tipa_function returned: ~p~n",[R2]),
  12. procidurka(Pid, update_n),
  13. R3 = tipa_function(Pid, get_n),
  14. io:format("after procidurka call tipa_function returned: ~p~n",[R3]).
  15.  
  16. procidurka(Pid, Request) ->
  17. Pid ! {self(), Request}.
  18.  
  19. tipa_function(Pid, Request) ->
  20. Pid ! {self(), Request},
  21. receive
  22. Response
  23. ->
  24. Response
  25. end.
  26.  
  27. loop(N) ->
  28. receive
  29. {From, get_n} ->
  30. From ! N,
  31. loop(N);
  32. {From, update_n} ->
  33. loop(N+1);
  34. {From, Other} ->
  35. From ! {error,Other},
  36. loop(N)
  37. end.
Success #stdin #stdout 0.06s 1749504KB
stdin
Standard input is empty
stdout
after procidurka call tipa_function returned: 1
after procidurka call tipa_function returned: 2
after procidurka call tipa_function returned: 3