This is the mail archive of the
mailing list for the libstdc++ project.
Re: Thread-safe libio
- To: firstname.lastname@example.org
- Subject: Re: Thread-safe libio
- From: Nathan Myers <email@example.com>
- Date: Sat, 15 May 1999 12:06:42 -0700 (PDT)
Jeff Anton <firstname.lastname@example.org> wrote:
> Ulrich Drepper wrote:
> > Andreas Gruenbacher <email@example.com> writes:
> > > a) use flockfile() / funlockfile() to lock the file for each I/O
> > > operation.
> > > Advantage: simple
> > > Disadvantage: high overhead
> > It is no question that this is the method to be used.
> There is a lot of reason _not_ to do this. If this kills performance
> then the whole of the iostream library will be shot. To my mind this
> option is completely unacceptable.
I agree with Jeff.
It would be madness to kill iostream performance, slowing it by two
orders of magnitude, unnecessarily. The Standard iostream facilities
define a way to get locking, and the Standard operators << and >> will
The approach Andreas suggested would penalize standard-conforming
code for no net benefit to non-standard code. The Standard-blessed
way to get thread-safety in streams is to place a counting mutex to
be claimed by the [io]stream::sentry constructor, and decremented or
released by its destructor. These operations would normally occur
much less frequently than per-character.