[erlang-questions] Selective receive issue

Vlad Dumitrescu vladdu55@REDACTED
Tue Aug 5 20:27:08 CEST 2008


On Tue, Aug 5, 2008 at 17:39, Robert Virding <rvirding@REDACTED> wrote:
> I am sorry I don't quite understand the problem. This is my understanding of
> the problem:
> - You can receive 4 different types of messages: 'start', 'stop',
> {input,Data} and junk.
> - You want to throw away all unknown (junk) messages.
> - 'Start'/'stop' messages act as some form of priority switches and if the
> last of then to arrive was a 'start' when you are ready to process then you
> will start processing, otherwise you will wait for a 'start' message to
> start processing.

Yes to all.

> - When you process input you take a known, specific number of {input,Data}
> messages from the queue, waiting if necessary to get them all.

The number is known, but may differ from one call to another of the
processing function. In most cases it will be the same, though.

> Is this correct or have I misunderstood you? Are there any more rules for
> the start/stop messages, for example they come in pairs or you count them,
> or do they just turn the process switch on/off?

Just on/off.

> How long time does the processing take? Not so much in seconds but in
> expected messages arriving during that period.

It depends, but even the incoming message stream is regulated in a
similar way, so if processing is slow the mailbox won't become too

> You will always get race conditions, for example you decide to start
> processing but before you begin a 'stop' will arrive which you ignore till
> later. How critical is the "exact" timing of processing the 'start'/'stop'
> messages?

It's not critical at all. The start/stop messages act as a soft flow
control mechanism, to ensure that the client of the process doesn't
get its mailbox flooded.

best regards,

> If this is what you mean then I think I may have a solution.

More information about the erlang-questions mailing list