comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew Heaney <matthew_heaney@acm.org>
Subject: Re: "recursive" accept statement ??
Date: 1998/12/15
Date: 1998-12-15T00:00:00+00:00	[thread overview]
Message-ID: <m3vhjdb2wo.fsf@mheaney.ni.net> (raw)
In-Reply-To: 3676575E.C3DB1843@lmco.com

"Marc A. Criley" <marc.a.criley@lmco.com> writes:

> Also, as a matter of general principle, since a task rendezvous blocks
> both caller and callee while the accept block is executing, one usually
> tries to make that rendezvous as brief as possible.  

That's a fine guideline, but one that doesn't apply in this case.  

> Here's a way of doing that (which also eliminates the scoping/deadlock
> issue):
> 
> task body trace is
>    S : string(1..Max_String_Length);
>    L : Natural;  -- should be the 1..Max_String_Length subtype
> begin
>    accept Put (str : string) do
>       S(str'range) := Str;
>       L := S'Length;
>    end Put;
>    -- Caller is now released
> 
>    Ada.text_io.put(S(1..L));         -- works fine
>    Put(S(1..L));                     -- Now outside of Put entry's scope
>    New_Line;
> 
> end trace ;

This code is wrong.  If the first index of the input string is anything
other than 1, then the Put will print garbage.

It's also wrong because it will deadlock.  The Put that immediately
follows the call to Ada.Text_IO.Put is actually a call to the task
entry.

Here is the corrected version:

task body trace is
begin

   accept Put (str : string) do

       Ada.text_io.put(str);
       Ada.text_IO.put(Str);
       New_Line;

   end Put;

end trace ;


 




  reply	other threads:[~1998-12-15  0:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-12-15  0:00 "recursive" accept statement ?? Frederic Voisin
1998-12-15  0:00 ` dennison
1998-12-15  0:00   ` Matthew Heaney
1998-12-15  0:00 ` Marc A. Criley
1998-12-15  0:00   ` Matthew Heaney [this message]
1998-12-15  0:00 ` David C. Hoos
1998-12-15  0:00 ` Tucker Taft
1998-12-23  0:00 ` Robert A Duff
replies disabled

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