This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] abort: Only flush file-based stdio streams before termination
On 08/21/2017 10:58 AM, Andreas Schwab wrote:
> On Aug 21 2017, Florian Weimer <fweimer@redhat.com> wrote:
>
>>> _IO_cleanup must do locking as well, of course.
>>
>> That means that a process cannot terminate if flockfile on a stream has
>> been called without a matching funlockfile. I don't think this is
>> permitted by POSIX, and wouldn't be a desirable implementation, either.
>
> Is it? That would simply be a programming error. Since POSIX requires
> locking on stdio I don't see how it can require exit to use no locking.
Is exit a function which references a FILE * object? What about fflush
(NULL)?
POSIX says this:
“
All functions that reference (FILE *) objects, except those with names
ending in _unlocked, shall behave as if they use flockfile() and
funlockfile() internally to obtain ownership of these (FILE *) objects.
”
I have no idea whether this expresses an intent that only explicit FILE
* references cause locking and, potentially blocking, or if this wording
is the result of a quick specification hack to add thread safety to stdio.
>> In a hypothetical, from-scratch stdio implementation, it should be
>> possible to implement flush-once without locking, but it requires
>> careful ordering of buffer pointer updates (or two locks instead of one).
>
> I don't think making stdio lock-free is desirable.
But neither is blocking on exit because a thread happens to have called
flockfile on a stdio stream.
Thanks,
Florian