Print statements in C++ are not threadsafe.
This language…!
Print statements in C++ are not threadsafe.
This language…!
@johan @luna
I would not describe having a nondeterministic race condition between format specifiers from different threads as being “thread safe,” except in the most uselessly pedantic way imaginable.
And no, I can’t think of another language that has this problem, because all of them use that magic native internal buffer we refer to as “local expression evaluation.”
@inthehands @luna they are thread safe.
The interleave pb is a different issue
I am not aware of languages that keep natively internal buffer per thread to avoid interleaving.
Do you have any example ?
@johan @inthehands @luna yeah, precisely. The "print statement" in C++ is the same as in C: printf and cousins.
operator<< is ... an operator and is not inherently more (or less) thread-safe than operator+ or operator=.
I also agree that is may be considered strange to promote an operator as the default way of printing.
@PaulDavisTheFirst @johan @luna
`cout <<` is the generally accepted idiom for printing to stdout in C++, no doubt able that — and yes, promoting that way is strange!
Technicalities about implementation(“`<<` is just another operator,” “it’s thread-safe at the level of individual stream insertions”, etc) are missing the point. The •standard idiom• is a footgun. That’s the point.
@inthehands @luna ok I see where we disagree.
Stream operators are not equivalent to print statement, each data being fed asap by design.
And I agree this might be considered as a strange choice to promote this as a default way of printing.
@johan @PaulDavisTheFirst @luna
Ha, that’s hilarious! Everything is terrible.
@inthehands @PaulDavisTheFirst @luna
Oh, researching other languages choices I discovered that Python as a very strange behavior:
https://stackoverflow.com/questions/42867866/what-makes-python3s-print-function-thread-safe#64283201
@inthehands @luna I think it might be better if it just threw a fucking pointer and crashed rather than do this shit.
GNU social JP is a social network, courtesy of GNU social JP管理人. It runs on GNU social, version 2.0.2-dev, available under the GNU Affero General Public License.
All GNU social JP content and data are available under the Creative Commons Attribution 3.0 license.