[erlang-questions] Completing the thought (a question about receive)

Hugo Mills hugo@REDACTED
Mon Feb 18 19:45:49 CET 2019


On Mon, Feb 18, 2019 at 10:55:35AM -0500, Donald Steven wrote:
> In a receive block, will the code 'thought' be completed before
> things goes 'back' to the beginning of the block, or does another
> incoming message received before the completion of that thought
> 'interrupt' the thought.

   Messages are processed singly and sequentially by any one
process. Each process has a message queue, and the only time that a
message comes off that queue is when receive is executed. The receive
takes the first matching message off the queue and then runs the code
for the branch matched. Only when another receive is encountered will
the queue be looked at again.

   So, basically, there's no pre-emption of the code within a process
-- each process runs its code linearly and sequentially without
interruption.

   HTH,
   Hugo.

>  If I haven't expressed that clearly,
> consider:
> 
>     receive
> 
>         {_, ComposerList, StartTime, XCoordinate, _, _, Distance,
> notdone} ->
> 
>             some code I want executed
>             some code I want executed
>             some code I want executed;
> 
>         {Base, _, StartTime, _, _, _, done}   ->
> 
>             some code I want executed
> 
>     end.
> 
> =============================
> 
> SO, will the three lines marked "some code I want executed" be
> executed always, or does a closely following message interrup it and
> send things back to the 'receive' (leaving some code perhaps not
> executed)?
> 
> (...trying to find a problem...)
> 
> Thanks.
> 
> Don
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

-- 
Hugo Mills             | We demand rigidly defined areas of doubt and
hugo@REDACTED carfax.org.uk | uncertainty!
http://carfax.org.uk/  |                                           Vroomfondel
PGP: E2AB1DE4          |                  The Hitch-Hikers Guide to the Galaxy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190218/04cf360d/attachment.bin>


More information about the erlang-questions mailing list