Note that there are some explanatory texts on larger screens.

plurals
  1. POErlang: priority receive
    primarykey
    data
    text
    <p>Priority receive in Erlang can easily be implemented as follows:</p> <pre><code>prio() -&gt; receive {priority, X} -&gt; X after 0 -&gt; receive X -&gt; X end end. </code></pre> <p>I am reading a paper called <a href="http://www.erlang-consulting.com/erlangworkshop07/erlang11-nystrom.pdf" rel="nofollow noreferrer">Priority Messaging made Easy</a> in which they describe the following problem:</p> <blockquote> <p>The main problem with the [code] example [above], is that we do not take into consideration that when evaluation is resumed from the inner blocking receive we may have more than one message in the mailbox. In a worst case scenario, all but the first, of potentially a huge number, of elements could be priority messages. In this scenario we would actually have accomplished the very opposite of what we intended to do.</p> </blockquote> <p>I don't completely get this.</p> <p>Question (1): I assume that the inner blocking receive will be 'called' (i.e. resumed) as soon as <strong><em>one</em></strong> message has arrived in the message queue, right? Is it realistic to assume that in the short time it takes to resume from the inner blocking receive, there would already be a whole bunch of messages waiting in the queue? </p> <p>Question (2): Also, the worst case scenario is described as a queue with one normal message an a lot of priority messages. Since all the receive clauses are first checked against the first message in the queue, and then against the second message in the queue, ...(source: this <a href="http://erlang.org/download/erlang-book-part1.pdf" rel="nofollow noreferrer">book</a>, page 69-70) shouldn't this be: a lot of normal messages with at the end of the queue a priority message?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload