From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8f513ebf6208d431 X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: Re: "recursive" accept statement ?? Date: 1998/12/15 Message-ID: #1/1 X-Deja-AN: 422600259 Sender: matt@mheaney.ni.net References: <1998Dec15.122957@lri.fr> <3676575E.C3DB1843@lmco.com> NNTP-Posting-Date: Tue, 15 Dec 1998 11:49:33 PDT Newsgroups: comp.lang.ada Date: 1998-12-15T00:00:00+00:00 List-Id: "Marc A. Criley" 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 ;