comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: open a file non-blocking ?
Date: Mon, 26 Feb 2018 17:41:09 +0100
Date: 2018-02-26T17:41:09+01:00	[thread overview]
Message-ID: <p71db5$tqf$1@dont-email.me> (raw)
In-Reply-To: <ccc5626a-784f-4fb5-81ec-033ebd9db7d2@googlegroups.com>

> 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


  parent reply	other threads:[~2018-02-26 16:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-24 19:42 open a file non-blocking ? patrick
2018-02-25  7:57 ` Dmitry A. Kazakov
2018-02-25 12:38   ` patrick
2018-02-26  2:53 ` Robert Eachus
2018-02-26  9:33   ` Dmitry A. Kazakov
2018-02-26 16:41   ` Jeffrey R. Carter [this message]
2018-02-26 16:55     ` Dmitry A. Kazakov
2018-02-27 17:14       ` patrick
2018-02-27 17:32         ` Dmitry A. Kazakov
2018-02-27 23:33           ` patrick
2018-02-28  1:13         ` Dennis Lee Bieber
replies disabled

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