[erlang-questions] Selective receive issue

Robert Virding rvirding@REDACTED
Tue Aug 5 17:39:47 CEST 2008


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

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? How long time does the
processing take? Not so much in seconds but in expected messages arriving
during that period.

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?

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

Robert

2008/8/5 Vlad Dumitrescu <vladdu55@REDACTED>

> Hi all,
>
> I have an example of a receive where I don't seem to be able to use the
> usual "dump any unrecognized messages" catch-all clause. I think it is also
> an example where channels could be useful, but the main question is whether
> I am missing the obvious or not.
>
> I have a process that takes {input, Data} messages from its mailbox and
> processes them (not necessarily one at a time). Flow control is implemented
> as a pair of 'start'/'stop' messages. The way I implemented the main loop is
> (simplified)
>
>   receive
>     start->Running = true, loop();
>     stop->Running = false, loop()
>   after 0 ->
>       if Running -> process_one_step(), loop();
>          true -> loop()
>       end
>   end,
>
> where the process_one_step() function may call
>
>   receive
>     {input, Data} -> ...
>   end
>
> one or several times (it is configurable by the clients).
>
> It seems to me that there is no place where I can put a '_->...;' clause
> without creating problems. So I'd like to ask if anyone sees another way to
> structure this that will allow rogue messages to be discarded.
>
> ------
> A solution that requires an EEP :-) is to introduce an extension to the
> receive statement that will explicitly  keep matched messages  in the
> mailbox. For example
>
> receive
>   Pattern -> keep(), loop();
>   Msg ->  process(Msg), loop()
> end
>
> keep() is the extension that says "leave the message in the mailbox and
> proceed". This way process() will be called with all messages except those
> matching Pattern
>
> Would something like that be useful, or are there already ways to achieve
> the same effect?
>
> best regards,
> Vlad
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080805/b433bc10/attachment.htm>


More information about the erlang-questions mailing list