News for hackers. Stuff that matters.
Re:There is no memory safety without thread safety by ferreiratb on Thursday July 24, 2025 @08:41PM (#44678122)
Can you elaborate on that?
Re:There is no memory safety without thread safety by wpollock on Thursday July 24, 2025 @09:50PM (#44678575)
A Java program can share mutable state between threads without synchronization, and it will compile and run. In Rust, such a program will not compile.
Re:There is no memory safety without thread safety by int_19h on Friday July 25, 2025 @01:12AM (#44679761)
Yes, but even so you will never see e.g. an invalid pointer value as the result of a torn memory write. Basically, no matter what you do with threads in Java, it will not segfault.

TFA's point is that (safe) Rust is also like that, but achieves it by restricting all cases where a torn write could be observed through its type system instead of VM's memory model.

Re:There is no memory safety without thread safety by dontlaugh on Friday July 25, 2025 @03:04AM (#44680420)
More specifically, Rust prevents data races.
Re:There is no memory safety without thread safety by BlackFly on Sunday July 27, 2025 @05:36AM (#44700044)
No, rust forces you to use a mutex but nothing will prevent you from making the mutex too small and creating tearing in your own data structures by sequentially modifying things covered by mutexes so that in between acquisition of the locks you are violating invariants. The borrow checker certainly helps however, but not without cost that was finally minimized when the scoped threads api came along.

Java has a very specific memory model, so the behavior of variables across threads is quite well defined. Basic variables can tear however (a 64bit long on a 32bit architecture) without the volatile keyword and that is quite different than rust.

Re:There is no memory safety without thread safety by dontlaugh on Sunday July 27, 2025 @05:43AM (#44700076)
You didn’t describe any data races.

What Rust prevents is very specific.

Re:There is no memory safety without thread safety by int_19h on Monday July 28, 2025 @01:16PM (#44712976)
OP described situations where you get observable invariant violations because of torn non-atomic writes. This is basically any case involving e.g. copying of variables that are larger than whatever's atomic for a given architecture. Say, a struct of 4 isize.