G2A Many GEOs
SHARE
TWEET

Linking 3 process - Rev 3

a guest Mar 13th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -module(procslinked).
  2. -compile([export_all]).
  3.  
  4. starter() ->
  5.   StarterPid = erlang:self(),
  6.   spawn(?MODULE, the_first_p, [StarterPid]),
  7.   receive
  8.     {Pid, init_done} ->
  9.       io:format("Receive init_done from P1~n"),
  10.       {Pid, okbeud}
  11.   end.
  12.  
  13. the_first_p(StarterPid) ->
  14.   MyPid = erlang:self(),
  15.   register(pidfirstp, MyPid),
  16.   StarterPid ! {MyPid, init_done},
  17.   spawn_link(?MODULE, the_second_p, [MyPid]),
  18.   the_first_p().
  19. the_first_p() ->
  20.   receive
  21.     {Pid, init_done} ->
  22.       io:format("Receive init_done from P2~n"),
  23.       {Pid, okbeud};
  24.     {From, "to first p", Msg} ->
  25.       From ! {self(), "the_first_p()", Msg}
  26.   end,
  27.   the_first_p().
  28.  
  29. the_second_p(StarterPid) ->
  30.   MyPid = erlang:self(),
  31.   register(pidsecondp, MyPid),
  32.   StarterPid ! {MyPid, init_done},
  33.   spawn_link(?MODULE, the_third_p, [MyPid]),
  34.   the_second_p().
  35. the_second_p() ->
  36.   receive
  37.     {Pid, init_done} ->
  38.       io:format("Receive init_done from P3~n"),
  39.       {Pid, okbeud};
  40.     {From, "to second p", Msg} ->
  41.       From ! {self(), "the_second_p()", Msg}
  42.   end,
  43.   the_second_p().
  44.  
  45. the_third_p(StarterPid) ->
  46.   MyPid = erlang:self(),
  47.   register(pidthirdp, MyPid),
  48.   StarterPid ! {MyPid, init_done},
  49.   the_third_p().
  50. the_third_p() ->
  51.   receive
  52.     {From, "to third p", Msg} ->
  53.       From ! {self(), "the_third_p()", Msg}
  54.   end,
  55.   the_third_p().
  56.  
  57. call_the_first() ->
  58.   pidfirstp ! {self(), "to first p", "Halo first p!"},
  59.   receive
  60.     {Pid, FuncName, Msg} ->
  61.       {Pid, FuncName, Msg}
  62.   end.
  63.  
  64. call_the_second() ->
  65.   pidsecondp ! {self(), "to second p", "Halo second p!"},
  66.   receive
  67.     {Pid, FuncName, Msg} ->
  68.       {Pid, FuncName, Msg}
  69.   end.
  70.  
  71. call_the_third() ->
  72.   pidthirdp ! {self(), "to third p", "Halo third p!"},
  73.   receive
  74.     {Pid, FuncName, Msg} ->
  75.       {Pid, FuncName, Msg}
  76.   end.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top