--- AnyEvent-MP/MP.pm 2009/08/05 23:50:46 1.34 +++ AnyEvent-MP/MP.pm 2009/08/06 10:21:48 1.35 @@ -25,6 +25,14 @@ rcv $port, [child_died => $pid] => sub { ... rcv $port, [_any_, _any_, 3] => sub { .. $_[2] is 3 + # linking two ports, so they both crash together + lnk $port1, $port2; + + # monitoring + mon $port, $cb->(@msg) # callback is invoked on death + mon $port, $otherport # kill otherport on abnormal death + mon $port, $otherport, @msg # send message on death + =head1 DESCRIPTION This module (-family) implements a simple message passing framework. @@ -620,15 +628,15 @@ =head1 AnyEvent::MP vs. Distributed Erlang -AnyEvent::MP got lots of its ideas from distributed erlang (erlang node -== aemp node, erlang process == aemp port), so many of the documents and -programming techniques employed by erlang apply to AnyEvent::MP. Here is a +AnyEvent::MP got lots of its ideas from distributed Erlang (Erlang node +== aemp node, Erlang process == aemp port), so many of the documents and +programming techniques employed by Erlang apply to AnyEvent::MP. Here is a sample: - http://www.erlang.se/doc/programming_rules.shtml - http://erlang.org/doc/getting_started/part_frame.html # chapters 3 and 4 - http://erlang.org/download/erlang-book-part1.pdf # chapters 5 and 6 - http://erlang.org/download/armstrong_thesis_2003.pdf # chapters 4 and 5 + http://www.Erlang.se/doc/programming_rules.shtml + http://Erlang.org/doc/getting_started/part_frame.html # chapters 3 and 4 + http://Erlang.org/download/Erlang-book-part1.pdf # chapters 5 and 6 + http://Erlang.org/download/armstrong_thesis_2003.pdf # chapters 4 and 5 Despite the similarities, there are also some important differences: @@ -649,11 +657,11 @@ needs a queue. AEMP is event based, queuing messages would serve no useful purpose. -(But see L for a more erlang-like process model on top of AEMP). +(But see L for a more Erlang-like process model on top of AEMP). =item * Erlang sends are synchronous, AEMP sends are asynchronous. -Sending messages in erlang is synchronous and blocks the process. AEMP +Sending messages in Erlang is synchronous and blocks the process. AEMP sends are immediate, connection establishment is handled in the background. @@ -666,10 +674,10 @@ AEMP guarantees correct ordering, and the guarantee that there are no holes in the message sequence. -=item * In erlang, processes can be declared dead and later be found to be +=item * In Erlang, processes can be declared dead and later be found to be alive. -In erlang it can happen that a monitored process is declared dead and +In Erlang it can happen that a monitored process is declared dead and linked processes get killed, but later it turns out that the process is still alive - and can receive messages. @@ -679,7 +687,7 @@ =item * Erlang can send messages to the wrong port, AEMP does not. -In erlang it is quite possible that a node that restarts reuses a process +In Erlang it is quite possible that a node that restarts reuses a process ID known to other nodes for a completely different process, causing messages destined for that process to end up in an unrelated process. @@ -695,7 +703,7 @@ =item * The AEMP protocol is optimised for both text-based and binary communications. -The AEMP protocol, unlike the erlang protocol, supports both +The AEMP protocol, unlike the Erlang protocol, supports both language-independent text-only protocols (good for debugging) and binary, language-specific serialisers (e.g. Storable). @@ -703,6 +711,21 @@ with a minimum of work while gracefully degrading fucntionality to make the protocol simple. +=item * AEMP has more flexible monitoring options than Erlang. + +In Erlang, you can chose to receive I exit signals as messages +or I, there is no in-between, so monitoring single processes is +difficult to implement. Monitoring in AEMP is more flexible than in +Erlang, as one can choose between automatic kill, exit message or callback +on a per-process basis. + +=item * Erlang has different semantics for monitoring and linking, AEMP has the same. + +Monitoring in Erlang is not an indicator of process death/crashes, +as linking is (except linking is unreliable in Erlang). In AEMP, the +semantics of monitoring and linking are identical, linking is simply +two-way monitoring with automatic kill. + =back =head1 SEE ALSO