[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] use unlocked stdio functions
From: |
Vito Caputo |
Subject: |
Re: [PATCH] use unlocked stdio functions |
Date: |
Wed, 14 Feb 2024 08:18:45 -0800 |
On Wed, Feb 14, 2024 at 10:59:57AM -0500, Chet Ramey wrote:
> On 2/5/24 10:47 PM, Grisha Levit wrote:
> > Bash makes many calls to stdio functions that may have unlocked_stdio(3)
> > equivalents. Since the locking functionality provided by the regular
> > versions is only useful in multi-threaded applications, it probably makes
> > sense for Bash to use the *_unlocked versions where available.
>
> Thanks for the patch; this looks like a great idea.
>
I thought this was only necessary for C programs built with pthreads
linked in / -D_REENTRANT. Is that no longer the case? Or has bash
started making use of pthreads?
When I first learned pthreads ages ago there was a substantial
performance hit to the classical stdio-using programs when you built
them w/pthreads. It was an important detail to be aware of at the time
because so many programs of the era had been written assuming things
like getc/ungetc and other character-granular stdio functions were fast
functions if not macros. But you didn't incur this hit if you didn't
make use of pthreads, which seemed like a conscious choice of the
pthreads creators to not impact all such existing software just because
a platform added pthreads support.
So unless my understanding is wrong/stale or bash has started using
pthreads, I don't think this should be necessary. But things do seem to
have evolved here; for instance we no longer explicitly add -D_REENTRANT
with gcc, instead using -pthread now. Would appreciate any input on the
current state of things in this area...
Thanks,
Vito Caputo