Advertisement
Guest User

Linking 3 process - Rev 1

a guest
Mar 9th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 1.13 KB | None | 0 0
  1. -module(newbie).
  2. -compile([export_all]).
  3.  
  4. starter() ->
  5.   spawn(?MODULE, the_first_p, []).
  6.  
  7. the_first_p() ->
  8.   register(pidfirstp, self()),
  9.   spawn_link(?MODULE, the_second_p, []),
  10.   receive
  11.     {From, "to first p", Msg} ->
  12.       From ! {self(), "the_first_p()", Msg}
  13.   end,
  14.   the_first_p().
  15.  
  16. the_second_p() ->
  17.   register(pidsecondp, self()),
  18.   spawn_link(?MODULE, the_third_p, []),
  19.   receive
  20.     {From, "to second p", Msg} ->
  21.       From ! {self(), "the_second_p()", Msg}
  22.   end,
  23.   the_second_p().
  24.  
  25. the_third_p() ->
  26.   register(pidthirdp, self()),
  27.   receive
  28.     {From, "to third p", Msg} ->
  29.       From ! {self(), "the_third_p()", Msg}
  30.   end,
  31.   the_third_p().
  32.  
  33. call_the_first() ->
  34.   pidfirstp ! {self(), "to first p", "Halo first p!"},
  35.   receive
  36.     {Pid, FuncName, Msg} ->
  37.       {Pid, FuncName, Msg}
  38.   end.
  39.  
  40. call_the_second() ->
  41.   pidsecondp ! {self(), "to second p", "Halo second p!"},
  42.   receive
  43.     {Pid, FuncName, Msg} ->
  44.       {Pid, FuncName, Msg}
  45.   end.
  46.  
  47. call_the_third() ->
  48.   pidthirdp ! {self(), "to third p", "Halo third p!"},
  49.   receive
  50.     {Pid, FuncName, Msg} ->
  51.       {Pid, FuncName, Msg}
  52.   end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement