Re:Java is not a safe language
by duped on Monday June 13, 2022 @01:43PM
(#31728830)
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.
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.