Meyer, OO and concurrency

Ulf Wiger <>
Sun Jul 17 16:41:00 CEST 2005

Den 2005-07-17 01:26:25 skrev David Hopwood  

> Various actor languages did have selective receive, for example the
> "communication handlers" of Act2 and Act3. In any case, selective
> receive does not affect the expressive power of a message passing
> model: it can be simulated, albeit inefficiently, by receiving
> unconditionally and then re-sending the message to self if necessary.

Actually, you can't do it like that. That could for example
cause your process to go into a tight loop consuming and
re-sending the same unwanted message while waiting for some
other message, which would have a rather nasty effect on
cpu load and timing characteristics.

One reason for using selective receive is to achieve scoping
of messages :a subroutine can wait for a given message, ignoring
unknown messages (c.f. gen_server:call()). But ignoring and
re-sending are not equivalent.

Re-sending unknown messages from a subroutine could have the
unwanted side-effect that two messages from some other process
arrive out of order, e.g. because one came in before the message
of interest to the subroutine, and the next one came in right
after it; re-sending the first would cause it to arrive after
the second message from the same process, thus messing up
a behaviour that is otherwise guaranteed by Erlang: that
two messages sent from one process to another will arrive
in the same order as they were sent.

Hoare suggested using buffer processes to achieve selective
receive. That would work, albeit inefficiently.


More information about the erlang-questions mailing list