PR 5432: Thread safety patches

Nathan Myers ncm-nospam@cantrip.org
Sat Jan 19 20:27:00 GMT 2002


On Sat, Jan 19, 2002 at 07:01:30PM -0800, Benjamin Kosnik wrote:
> > To make iostreams thread-safe, we also need for the sentry constructor 
> > and destructor to claim/release a counting mutex.
> 
> Can't the same mechanism that string is using be re-used for this 
> purpose? 

No.  Atomic-increment never blocks.  It's useful only to tell one thread
to run something when it hits zero.  

The sentry constructor has to block if another sentry object is bound 
to the same stream, and then wake up when the destructor for the other 
sentry object completes.   It has to be a counting mutex because some 
operators << and >> use others underneath.

Nathan Myers
ncm at cantrip dot org



More information about the Libstdc++ mailing list