From: Luke D. <cod...@ho...> - 2003-04-15 01:38:44
|
----- Original Message ----- From: "Jeff Williams" <jwi...@mf...> To: <min...@li...> Sent: Monday, April 14, 2003 11:12 PM Subject: [Mingw-users] cout and threading > I am using multiple threads with gcc 3.2.2 (mingw). I am also using STLport and I am using their streams implementation so perhaps this question is not suited for this list, but I thought I'd start asking here. > > The problem, is that when using cout from multiple threads the characters get "merged together"; however, if I use printf it seems to lock on a per line basis so my lines of output are never garbled together... > > Any suggestions on what I need to do in order for cout to exhibit the same behavior as printf when using threads? You must synchronise access to cout yourself to avoid multiple threads outputting at the same time (or accessing the same iostream simultaneously at all). Is it true anyway that printf() locks per-line or is it really per call to printf? If you are outputting a line with multiple calls to "cout <<" then it is not reasonable to expect any library to lock across multiple calls and wait for a newline. > > BTW: I noticed the same behavior when using VC++ as the compiler and *not* using STLPORT. Which is why I started asking here first (I was thinking it might be a compiler issue or at the very least someone here has encountered this) > > Jeff Luke |