Skip to content

Instantly share code, notes, and snippets.

@rkmax
Created December 8, 2011 14:34
Show Gist options
  • Save rkmax/1447141 to your computer and use it in GitHub Desktop.
Save rkmax/1447141 to your computer and use it in GitHub Desktop.
Ejemplo de mensajes entre procesos
-module(ping_pong). % Nombre del modulo
-compile(export_all). % Esto hace todas las funciones publicas fuera del modulo
ping(0, Pong_PID) ->
Pong_PID ! finished,
io:format("ping finished~n", []);
ping(N, Pong_PID) ->
Pong_PID ! {ping, self()},
receive
pong ->
io:format("Ping received pong~n", [])
end,
ping(N - 1, Pong_PID).
pong() ->
receive
finished ->
io:format("Pong finished~n", []);
{ping, Ping_PID} ->
io:format("Pong received ping~n", []),
Ping_PID ! pong,
pong()
end.
start() ->
Pong_PID = spawn(mess_pass, pong, []),
spawn(mess_pass, ping, [3, Pong_PID]).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment