I want to ask exactly the same question as was asked here: Synchronizing STD cout output multi-thread with the single exception that i DO NOT have control over the code in which boost::thread s are used (that code is internal to this library, and I should not / want not to touch it, unless this problem can not be solved in any other way, in which case I could add it to my fork of the library.)
The library at a certain time spawns 4 threads (I'm on a mid-2010 MacBook Pro using OSX 10.10) in the C++ code that is executed in a single thread I use cout for logging, like so:
cout << "Writing file: " << "\n" << xmlFileName << endl;
This output gets garbled due to multi-threading so it gets hard to understand what is going on in a single thread at any given moment...
How can I get the output synchronized ? The project uses Boost 1.57.0 so I can use that. I have never had to deal with multi-threading before but I understand the concepts and problems that arise. I have also seen some examples on SO but all of them require access to the code that spawns threads, either using a shared Mutex passed to the threads or using a lockGuard.
Although I have the feeling I can not escape modifying the library code, I hope that this is somehow possible?