Created
April 29, 2012 19:28
-
-
Save kerryb/2552856 to your computer and use it in GitHub Desktop.
Failing Erlang monitor
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
Erlang R15B (erts-5.9) [source] [64-bit] [smp:4:4] [async-threads:0] [hipe] [kernel-poll:false] | |
Eshell V5.9 (abort with ^G) | |
1> c(doubler). | |
{ok,doubler} | |
2> c(monitor). | |
{ok,monitor} | |
3> | |
3> monitor:start(). | |
new | |
4> doubler:double(doubler, 2). | |
4 | |
5> doubler:double(doubler, ""). | |
<0.44.0> exited: {badarith,[{doubler,loop,0,[{file,"doubler.erl"},{line,7}]}]}. | |
=ERROR REPORT==== 29-Apr-2012::20:22:52 === | |
Error in process <0.44.0> with exit value: {badarith,[{doubler,loop,0,[{file,"doubler.erl"},{line,7}]}]} | |
...and there it stops, and I have to kill the console. The monitor seems to be restarting it OK, but I'm obviously doing something wrong. |
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(doubler). | |
-export([loop/0, double/2]). | |
loop() -> | |
receive | |
{Pid, N} -> | |
Pid ! (N * 2), | |
loop() | |
end. | |
double(To, N) -> | |
To ! {self(), N}, | |
receive | |
Result -> Result | |
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(monitor). | |
-export([loop/0, start/0]). | |
loop() -> | |
process_flag(trap_exit, true), | |
receive | |
new -> | |
register(doubler, spawn_link(fun doubler:loop/0)), | |
loop(); | |
{'EXIT', From, Reason} -> | |
io:format("~p exited: ~p.", [From, Reason]), | |
monitor ! new, | |
loop() | |
end. | |
start() -> | |
register(monitor, spawn(fun monitor:loop/0)), | |
monitor ! new. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment