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,897 times
4

Lightness Races in Orbit
- 378,754
- 76
- 643
- 1,055

Nico Engels
- 407
- 2
- 12
2 Answers
7
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,976
- 1
- 27
- 45
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
- 656
- 1
- 9
- 17