Joe,
Joseph M. Newcomer schrieb:
****
cout is not thread-safe. Therefore, any attempt to use it must be protected by a
synchronization primitive (such as a CRITICAL_SECTION). Otherwise, you can experience
heap damage because two or more threads will actually overwrite buffers and damage the
heap (I've seen this happen to people who used cout in this fashion).
Can you please tell where you found this information?
I just looked it up in MSDN and found in
http://msdn2.microsoft.com/en-us/library/c9ceah3b(VS.80).aspx:
"The iostream classes follow the same rules as the container classes, with one
exception. It is safe to write to an object from multiple threads. For example,
thread 1 can write to cout at the same time as thread 2. However, this can
result in the output from the two threads being intermixed."
Is thread safety of iostreams a (new?, non-standard?) feature in VS2005 and not
portable? I have used iostream in multiple threads in the past, and I wonder if
I produced non-portable code?
has always been there. (There's nothing anyone except the person using cout
can do about the latter. Ditto for printf and friends.)