Flushing libgfortran from C
Tobias Burnus
burnus@net-b.de
Thu Mar 3 10:48:00 GMT 2011
On 03/03/2011 11:26 AM, N.M. Maclaren wrote:
> Er, no. That's stderr you are thinking of.
No, I am actually thinking of stdout (and stderr), but I am thinking of
a different buffering.
There is some internal buffering in libgfortran, which is needed if one
decides to all of a sudden to change items in the current record (T edit
descriptors), but which is also used for performance reasons. This
libgfortran internal buffering is turned off for stdout, stderr, stdin,
sockets (fifo), and pipes - and if one sets an environement variable for
all units. Thus, for those units, the libgfortran's buffer is flushed
after each I/O transfer statement. However, then the next buffer kicks
in: The one of the libc library, which can be flushed by fflush. And
next and last accessible one is the operating system's I/O buffering,
which can by flushed by fsync.
Calling gfortran's "flush" deals with the internal buffer (which should
be off for stdout) and calls fflush. I don't know whether that is
sufficient, but it should be a first step to get I/O.
>> (I admit that having a call which properly shuts down the library
>> would be sometimes useful.)
> I would say "badly needed".
Well, as it is registered as exit hook ("__attribute__((destructor))")
having an explicit call is not as important as without such an hook.
> On this matter, my suspicion is that the Rice people have got it wrong.
> I can't think of any good reason to call _exit in that case.
(I also have no idea why exit is not sufficient.)
Tobias
More information about the Fortran
mailing list