Skip to content

Instantly share code, notes, and snippets.

@cybergrind
Last active December 10, 2015 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cybergrind/4502558 to your computer and use it in GitHub Desktop.
Save cybergrind/4502558 to your computer and use it in GitHub Desktop.
-module(tr).
-compile([export_all]).
-define(PRIORITIES, [high, med, low]).
next_priority(high) ->
med;
next_priority(med) ->
low;
next_priority(low) ->
any.
proc1(any) ->
receive
{_, M} ->
io:format("~p~n", [M]),
timer:sleep(1000),
proc1(high)
end;
proc1(P) ->
receive
{P, M} ->
io:format("~p~n", [M]),
timer:sleep(1000),
proc1(high)
after
0 ->
proc1(next_priority(P))
end.
proc2() ->
Pid = spawn(tr, proc1, [high]),
Pid ! {low, low},
Pid ! {med, med},
Pid ! {high, high}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment