This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
Re: Thread-safe libio
- To: libstdc++@sourceware.cygnus.com
- Subject: Re: Thread-safe libio
- From: Nathan Myers <ncm@best.com>
- Date: Sat, 15 May 1999 12:06:42 -0700 (PDT)
Jeff Anton <jaanton@jps.net> wrote:
> Ulrich Drepper wrote:
> > Andreas Gruenbacher <a.gruenbacher@infosys.tuwien.ac.at> 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
use it.
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.
Nathan Myers
ncm@cantrip.org