Are there any problems with multiple threads writing to stdout?
> > > However, even if there are no problems, you may be seeing interleaved > > >output: > > > > > > example: > > > > > > printf(“x=%d, y=%d\n”, x, y); > > > > > >there is no guarantee that x and y will appear on the same line > > > > Surely, printf() will lock the stream object (if you use the MT safe glibc2), > > no? > > Not on Linux, or any other UNIX variant I’ve dealt with. UNIX is used > to it, even before threads. stdout on NT doesn’t make sense unless it’s > a console appliation. For POSIX conformance, printf() must lock the process’ stdio file stream. That is, the output is “atomic”. Thus, if two threads both call a single printf() simultaneously, each output must be correct. E.g., for printf (“%d, %d\n”, 1, 2); printf (“%s, %s”\n”, “abc”, “def”); you might get 1, 2 abc, def or you might get abc, def 1, 2 but no more “bizarre” variations. If you do, then the implementation you’re using is broken. There is another level of complication, though, if you’re talking about the seque