comp.lang.ada
 help / color / mirror / Atom feed
From: Ben Brosgol <brosgol@world.std.com>
Subject: Re: Neater entry point code
Date: 1997/12/18
Date: 1997-12-18T00:00:00+00:00	[thread overview]
Message-ID: <3498AF47.7B75@world.std.com> (raw)
In-Reply-To: 34989E2A.93EF7271@dsto.defence.gov.au


Mark Rutten wrote:
> 
> The code that I have at the moment looks like
> 
>     while Execute'Count /= 0 loop
> 
>       accept Execute( In_Msg: in Message_Typ ) do
>         Msg := In_Msg;
>       end Execute;
> 
>       Add_Msg(Msg);
> 
>     end loop;
> 
>     Execute_Stuff;
> 
> What I'm trying to do is extract anything that's queued up
> on the entry point and then go off and do something else.
> 
> Is there a neater way of doing this? I don't want to use another
> task to do either Add_Msg or Execute_Stuff.
> 
> Thanks,
> Mark

This code has a couple of race conditions. 

(1) Just after Execute'Count evaluates to 0, a call may arrive, but it
will not be accepted.  Presumably either the program doesn't care if it
misses such calls, or else some other part of the code will accept it
later (or perhaps the entire fragment shown is in an outer loop).

(2) Potentially more seriously, assume that there is a call pending on
Execute, and thus Execute'Count /=0 evaluates to True, but before
control reaches the accept statement the calling task either times out
or is aborted.  Then the task containing the code fragment will be
blocked at the accept, and it will not be able to proceed until another
call arrives. 

(3) A call of Execute that arrives while another one is being accepted
will be served by a later iteration of the loop; I assume that was
intended.  

Whether there is a "neater way" to solve the problem depends on whether
these race conditions are a concern.  If you need to solve (2) then you
will probably want to reformulate the program using a protected object
(with a protected entry for Execute), and a signaling task calling a
protected procedure to indicate that it is time to service the callers.  

Ben Brosgol
brosgol@aonix.com




  parent reply	other threads:[~1997-12-18  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-12-18  0:00 Neater entry point code Mark Rutten
1997-12-17  0:00 ` Matthew Heaney
1997-12-18  0:00 ` Ben Brosgol [this message]
1997-12-18  0:00 ` Jean-Pierre Rosen
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox