News for hackers. Stuff that matters.
Re:Tell HN: Python's print function is thread-unsafe by kerneloops on Monday January 01, 2024 @03:35AM (#38830456)
A survey of some other languages:

C printf: MT-Safe locale.

C++ std::cout: safe, unless you call sync_with_stdio(false).

JVM System.out.println: safe in common JVMs.

C# Console.WriteLine: safe.

Go fmt.Printf: safe.

Rust println!: safe.

Ruby puts: safe.

So it seems that Python is the outlier here.

Re:Tell HN: Python's print function is thread-unsafe by vitaut on Monday January 01, 2024 @11:49AM (#38833141)
std::cout is thread-safe but because of the concatenation-based API parts of the message may interleave. C++23 std::print is safe (and the output doesn't interleave).

See https://vitaut.net/posts/2023/print-in-cpp23/.