Thread safety of cout

Dan Evison devison@pacificit.co.nz
Fri Oct 8 00:58:00 GMT 2004


BTW, I think what caught me out was I used to work at two firms that both
used the Rogue Wave implementation of iostreams, that does provided locking
on cout/cerr:
  http://www.roguewave.com/support/docs/sourcepro/stdlibug/44-1.html

While it is arguably unnecessary, perhaps this documentation
http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#9
could have a sentence added such as:
 "Of course any use of a stream object (such as cout ) by multiple threads
must be protected with locks."

Dan


----- Original Message ----- 
From: "Paolo Carlini" <pcarlini@suse.de>
To: "Nathan Myers" <ncm-nospam@cantrip.org>
Cc: <libstdc++@gcc.gnu.org>
Sent: Friday, October 08, 2004 12:43 PM
Subject: Re: Thread safety of cout


> Nathan Myers wrote:
>
> >I would expect any program that uses cout in more than one thread,
> >without locking, to fail in random ways.  A deadlock or crash means
> >you got lucky, because by the specs in that case it's allowed to
> >erase your disk and impregnate your sister.
> >
> >
> :)
>
> Something that I still don't grasp completely is the difference between
> fwrite / fwrite_unlocked and fflush / fflush_unlocked: the (glibc (*))
specs
> don't seem to imply that the first two, respectively, take a lock?!? In
that
> case, I would exclude at least pregnancy... ;)
>
> Paolo.
>
> (*) To be clear with everybody, there is no such a thing as
fwrite_unlocked
> and fflush_unlocked in the C standard, neither in Posix...
>



More information about the Libstdc++ mailing list