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.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: open a file non-blocking ? Date: Mon, 26 Feb 2018 17:41:09 +0100 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <6c0d9514-97e0-4c5e-9b7d-b247c2ca0ced@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 26 Feb 2018 16:41:09 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="8ad993cec2f9bba53d589d069eea1305"; logging-data="30543"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/GNwHti4WBqbdeIgr4Skyp8JF26Oltn5Q=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 In-Reply-To: Content-Language: en-US Cancel-Lock: sha1:MkFp4jL80yPzDvXEC1bW52TJp98= Xref: reader02.eternal-september.org comp.lang.ada:50652 Date: 2018-02-26T17:41:09+01:00 List-Id: > On Saturday, February 24, 2018 at 2:42:30 PM UTC-5, pat...@spellingbeewinnars.org wrote: > > There does not seem to be an option to open a file non-blocking. Is there a way? I guess it depends on what you mean by non-blocking. Some of the responses on here seem to think it means you can issue a write to the file and it returns immediately, without waiting for the write to file to complete. If that's the case, the normal way to deal with this within Ada is something like package Write_Queue_Interfaces is new Ada.Containers.Synchronized_Queue_Interfaces (Element_Type => Ada.Strings.Unbounded.Unbounded_String); package Write_Queues is new Ada.Containers.Unbounded_Synchornized_Queues (Queue_Interfaces => Write_Queue_Interfaces); Write_Queue : Write_Queues.Queue; task Writer; task body Writer is File : Ada.Text_IO.File_Type; Item : Ada.Strings.Unbounded.Unbounded_String; begin -- Writer Ada.Text_IO.Create (File => File, Name => ...); Forever : loop Write_Queue.Dequeue (Element => Item); Ada.Text_IO.Put_Line (File => File, Item => Ada.Strings.Unbounded.To_String (Item) ); end loop Forever; end Writer; Probably in reality you'd want a way to exit the loop and close the file. A task wishing to write Msg to the file does Write_Queue.Enqueue (New_Item => Ada.Strings.Unbounded.To_Unbounded_String (Msg) ); -- Jeff Carter "He nevere yet no vileynye ne sayde In al his lyf unto no maner wight." Canterbury Tales 156