Re:Java is not a safe language
by commandlinefan on Monday June 13, 2022 @01:00PM
(#31728243)
Sounds more or less (and pardon me if I'm oversimplifying) Java's "synchronized" keyword that most people stay away from just because it slows the code down so much you don't get the benefit of parallelization.
They couldn't be more different.
Java's synchronized keyword changes how code is interpreted to use expensive locking and data fences in order to prevent logical race conditions.
Rust's semantics do not alter the compiled code or insert any locking behavior. They prevent you from writing incorrect code to begin with.
In other words, Rust doesn't do anything magical to deal with data races at run time. It prevents you from expressing programs that have data races in the first place. It's a compile time analysis, not a run time behavior.
Re:Java is not a safe language
by commandlinefan on Monday June 13, 2022 @02:19PM
(#31729299)
Interesting, thanks for clarifying.
Safe Rust forbids this through ownership and move semantics along with lifetime analysis. You may create any number of immutable aliases to data, or exactly one mutable alias. You cannot mix the two.
Unsafe allows you to (kind of) sidestep the automatic checking, but its your responsibility to uphold those conditions.