Subj : Re: Is std::cerr thread safe To : comp.programming.threads From : Maciej Sobczak Date : Wed Jul 20 2005 10:52 pm Sean Kelly wrote: > The STL is guaranteed to be thread-safe No, it isn't (and cerr is not STL). It is rather considered to be a Quality of Implementation issue (you will not find it in the standard) that the program at least does not crash when I/O is accessed in a MT way. > std::ostringstream ostr; > ostr << "error: " << errno << '\n'; > std::cerr << ostr.rdbuf(); Even if cerr has this Quality of Implementation guarantee, I would not bet my money that it is at the level which would be appropriate above. Try with *very* long messages (to overflow any potential buffer on the road) to see where the synchronization is in your particular library implementation. > The preferable alternative would be to wrap writes in a critical > section Definitely. Some tricks with temporary objects may help as well, at least with single-instruction output schemes this: myerr << "some " << 123 << " lengthy " << abc << " error " << xyz << " message\n"; -- Maciej Sobczak : http://www.msobczak.com/ Programming : http://www.msobczak.com/prog/ .