This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Thread safety of cout


On Fri, Oct 08, 2004 at 01:43:19AM +0200, Paolo Carlini 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... ;)

Probably the POSIX people who (rashly) chose to ihave putc() and getc() 
take a lock by default felt that special optimized versions of fwrite() 
and fflush() were not necessary, because they would not be called 
frequently enough for the locking overhead to matter.  I would imagine 
further that the glibc people added the "_unlocked" versions for 
what they thought of as completeness.

Nathan Myers
ncm@cantrip.org


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]