[erlang-questions] [RFC] smarter receive
Jay Nelson
jay@REDACTED
Fri Nov 10 04:14:33 CET 2006
I wasn't sure that this message was about "proposal to enhance message
receive"
because the thread name changed. You quoted a book I never mentioned and
then had code that looked very similar to mine. I assume this is
somehow related
and will try to answer.
> Why not remember this position for next time?
> Since the test is constant none of the already scanned messages will
match
> next time either!
This only helps in the case of constant data. If there is a variable
that could
change because it is a loop argument or the result of another receive, then
you must resort back to the full scanning method. This would solve the
problem
in some cases, but not all, while making the implementation more complex.
>Remaining to solve is where to start the scan - prio2a and prio2b
could have
> different message_scan_locations so begin with the oldest.. which one is
> oldest?
You don't want to change the fundamental semantics of receive in that
messages
are scanned from earliest to latest, and that the order of pattern
clauses in a
receive statement matters (they are evaluated sequentially against a single
message). It is possible to arrange this in your scenario, but you wouldn't
want to adopt an approach that makes the bookkeeping required to manage
the semantics to be too involved. Right now message receive is simple and
fast to perform, therefore it is highly reliable.
It only becomes slow when you combine selective receive with a very long
message queue. This can happen when there are multiple requesters filling
the queue, or the server handling requests has a lot to do for a single
request.
jay
More information about the erlang-questions
mailing list