Created
December 17, 2014 21:19
-
-
Save hhimanshu/117bd0fe9a7a078fbc7c to your computer and use it in GitHub Desktop.
Create 2 process and send M messages back and forth between them
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
% http://www.erlang.org/course/exercises.html#conc | |
-module(process). | |
-export([loop/0]). | |
loop() -> | |
receive | |
{From, Message} -> io:format("received [~p] from [~p]~n", [Message, From]), | |
loop() | |
end. |
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(process_function). | |
-compile(export_all). | |
start(M) -> | |
P1 = spawn(process, loop, []), | |
P2 = spawn(process, loop, []), | |
io:format("instantiated process ~p~n", [P1]), | |
io:format("instantiated process ~p~n", [P2]), | |
message(P1, P2, M), | |
message(P2, P1, M). | |
message(From, To, M) -> | |
[To ! {From, X} || X <- lists:seq(1,M)]. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment