Performance of selective receive

Pascal Brisset <>
Tue Nov 15 13:50:43 CET 2005


Richard A. O'Keefe writes:
 > So any particular instance of the receive shown above can be
 > characterised by {<<the code address>>, Port}.

Yes, this would probably take care of the selective receives in
file:write, gen_tcp:send and so on.

Things are more complicated with gen_server:
    receive {Mref, Reply} -> ...
Since the bound variable Mref has a different value on each invocation,
you can't use it as a key for the cache as you do with Port.

You could assume that if a receive statement ever uses a pattern
{Mref,Reply} where Mref is a monitoring reference, then it is
worth cacheing the fact that "among the first N queued messages,
there is no pair whose first element is a monitoring reference".
That might be enough for all practical purposes.

-- Pascal




More information about the erlang-questions mailing list