Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Are there any problems with multiple threads writing to stdout?

problems stdout threads writing
0
0 Posted

Are there any problems with multiple threads writing to stdout?

0
0

> > > 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

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123