Skip to content

Instantly share code, notes, and snippets.

@stantona
Created May 20, 2013 18:28
Show Gist options
  • Select an option

  • Save stantona/5614214 to your computer and use it in GitHub Desktop.

Select an option

Save stantona/5614214 to your computer and use it in GitHub Desktop.
-module(process_exc).
-export([start/1, proc/1]).
start(M) ->
N1 = spawn(process_exc, proc, [M]),
N2 = spawn(process_exc, proc, [M]),
N1 ! {N2, ping}.
proc(M) ->
proc(M, 0).
proc(M, M) ->
io:format("~p Process exiting...~n", [self()]);
proc(M, C) ->
receive
{From, ping} ->
print(ping, C),
From ! {self(), pong},
proc(M, C+1);
{From, pong} ->
print(pong, C),
From ! {self(), ping},
proc(M, C+1);
_ ->
io:format("Unrecognized message...~n"),
proc(M, C)
end.
print(M, C) ->
io:format("~p received ~p: ~p~n", [self(), M, C]).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment