comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Re: File output and buffering
Date: Sat, 23 Aug 2008 15:00:14 -0700 (PDT)
Date: 2008-08-23T15:00:14-07:00	[thread overview]
Message-ID: <4e375604-970f-41ab-9691-dd9abd3e75b9@d45g2000hsc.googlegroups.com> (raw)
In-Reply-To: Q7adnfmCI6Ly6S3VnZ2dnUVZ_jOdnZ2d@earthlink.com

On 23 Sie, 22:34, Dennis Lee Bieber <wlfr...@ix.netcom.com> wrote:

> > Then we have a different notion of "synchronously".
> > When I write something to the file, the operation is synchronous when
> > the program *waits* for the transfer to complete.
>
>         If I may slip in, since this thread has wandered into comparisons
> that even I can't follow...
>
>         Define "complete"

So that the program can immediately terminate and still have the data
reliably stored.
Think about log files of various kinds (including database write ahead
logs) and the importance of having something confirmed.

>         Most I/O systems I've encountered are buffered by the OS...

Of course - and not only that. There are buffers everywhere, even in
hard drives. The semantics of output operation from the program point
of view can be, however, described in terms of reasonably understood
best-effort or pushing data as far as it makes sense. For example, if
the hard drive can guarantee reliable storage at the level of its own
buffers, then it can confirm reception of the data without actually
storing them on plates. From the point of view of the program, the I/O
operation can be considered as finished, because from that point
nothing can mess things up.

> As far
> as an application is concerned, an I/O "write" operation is "complete"
> when the OS accepts the packet for buffering.

Exactly - provided that the packet was *copied* to OS buffers as
opposed to just passing pointer to programs data.

In practical terms:

Ada.Text_IO.Put_Line (File, "Hello");
Ada.Text_IO.Flush (File);
--  here we can crash without losing data

I consider the output operation above (triggered or ensured by Flush)
to be *synchronous with respect to the program*. When the Flush
operation returns the control back to the program, the data is already
stored in the external file (as AARM calls it), whatever that means,
even if the "external file" includes several layers of buffers. From
the program's perspective, it is "done".

If you want to contrast the above with asynchronous version, the
output operation can be initiated by the program but the program would
be allowed to continue without any guarantee related to the amount of
data being stored (and with some provisions to get the status later
on).

Short coverage of what all this means in the context of databases:

http://www.orafaq.com/node/93

It is really well written.

I hope that you get what I'm trying to say here. Well, at least I'm
sure that I'm not inventing anything new.

--
Maciej Sobczak * www.msobczak.com * www.inspirel.com

Database Access Library for Ada: www.inspirel.com/soci-ada



  parent reply	other threads:[~2008-08-23 22:00 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-19 20:27 File output and buffering Maciej Sobczak
2008-08-20  6:45 ` Georg Bauhaus
2008-08-20  8:43 ` Maciej Sobczak
2008-08-20  8:59   ` Maciej Sobczak
2008-08-20  9:21     ` Dmitry A. Kazakov
2008-08-20 14:44       ` Maciej Sobczak
2008-08-20 15:39         ` Dmitry A. Kazakov
2008-08-21  7:10           ` Maciej Sobczak
2008-08-21  9:24             ` Dmitry A. Kazakov
2008-08-21 20:54               ` Maciej Sobczak
2008-08-21 21:27                 ` Dmitry A. Kazakov
2008-08-22 11:53                   ` Maciej Sobczak
2008-08-22 13:22                     ` Dmitry A. Kazakov
2008-08-22 21:41                       ` Maciej Sobczak
2008-08-23 10:25                         ` Dmitry A. Kazakov
2008-08-23 13:41                           ` Steve
2008-08-23 14:33                             ` Dmitry A. Kazakov
     [not found]                         ` <Q7adnfmCI6Ly6S3VnZ2dnUVZ_jOdnZ2d@earthlink.com>
2008-08-23 22:00                           ` Maciej Sobczak [this message]
2008-08-20 13:19     ` Georg Bauhaus
2008-08-20 14:41       ` Maciej Sobczak
replies disabled

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