3 ms·
Rust can only guarantee that no data race will happen. Other race conditions are still possible, so I don’t really see Rust that much safer than Java. Concurren
by kaba0 5y ago
Rust can only guarantee that no data race will happen.
Other race conditions are still possible, so I don’t really see Rust that much safer than Java. Concurrency is hard everywhere.
- charleslmunger 5y agoIndeed. I recommend using tsan for java. https://wiki.openjdk.java.net/display/tsan/Main https://wiki.openjdk.java.net/display/tsan/Main But the types of races I struggle with in java I suspect are similarly hard in Rust. Here's two pieces of concurrent code I struggled with: https://github.com/google/guava/blob/master/guava/src/com/google/common/util/concurrent/ExecutionSequencer.java#L286 https://github.com/google/guava/blob/master/guava/src/com/go... https://github.com/google/guava/blob/master/guava/src/com/google/common/util/concurrent/SequentialExecutor.java#L162 https://github.com/google/guava/blob/master/guava/src/com/go... I'm not sure reasoning about the correctness of those would be easier in Rust, but if there are any rust experts reading this I'd love your perspective.
- kaba0 5y agoThanks, I haven’t seen tsan before. Java also has JML but I don’t know how much does it help regarding concurrency.
- Matthias247 5y agoInteresting - didn’t knew tsan is now available for Java. Which JDK version is it available for? The linked wiki isn’t super clear on this. But given it seems a 2020 Addition I guess only for rather recent ones.
- Matthias247 5y agoWhile that is the only guarantee it can provide - in practice it ends up being a lot more powerful. Eg most multithreading issues in Java occur due to totally missing synchronization - because developers either didn’t think about threads or didn’t have enough experience to apply correct synchronization. In Rust the compiler would already have complained about these cases, and eg the design of the Mutex type - which wraps data instead of standing next to it - makes it hard to abuse.