Reputation: 447
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?
Upvotes: 5
Views: 3487
Reputation: 676
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.
Upvotes: 2
Reputation: 7344
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.
Upvotes: 7