Created
December 8, 2011 14:34
-
-
Save rkmax/1447141 to your computer and use it in GitHub Desktop.
Ejemplo de mensajes entre procesos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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