What are the uses of the new C++20 std::osyncstream (http://en.cppreference.com/w/cpp/io/basic_osyncstream)? Isn't the std::ostream already thread-safe?
Asked
Active
Viewed 1,087 times
3
Lightness Races in Orbit
- 369,052
- 73
- 620
- 1,021
Nico Engels
- 87
- 7
2 Answers
6
According to How to easily make std::cout thread-safe?
it looks like it is not thread-safe. They even (the first answer in that question) suggest to make a wrapper, which is basically what std::osyncstream offers.
lilezek
- 6,438
- 1
- 23
- 44
2
Writing to a log file or to std::cout from different threads, atomically.
That's the first thing I thought of.
In such a scenario, written data won't be interleaved or garbled.
bit2shift
- 586
- 1
- 8
- 17