multiple threads writing to std::cout or std::cerr
I have OpenMP threads that write to the console via cout and cerr. This of course is not safe, since output can be interleaved. I could do something like #pragma omp critical(cerr) { cerr << "my variable: " << variable << endl; } It would be nicer if could replace cerr with a thread-safe version, similar to the approach explained in the valgrind DRD manual ( http://valgrind.org/docs/manual/drd-manual.html#drd-manual.effective-use ) which involves deriving a class from std::ostreambuf. Ideally in the end I would just replace cerr with my own threaded cerr, e.g. simply: tcerr << "my variable: "