by ultimaweapon · 1y ago · 0 comments
The major problem for me with Rust is deadlock. In Rust it is very easy to cause a deadlock compared to other languages. In other languages you need to think a lot before locking a mutex but in Rust you just `foo.lock().unwrap()`, which can easily cause a deadlock if you have multiple mutexes and someone in your team does not aware the lock order.
[0] https://doc.rust-lang.org/edition-guide/rust-2024/temporary-...
[0]: e.g., https://docs.rs/lock_ordering/latest/lock_ordering
It was one of the usual "if you'd have rewritten it in rust you'd have had no problems" posts. But instead of the usual memory safety list, they also added no deadlocks to the benefits.
It's easy to write code that deadlocks; make two shared pointers to the same mutex, then lock them both. This compiles without warnings:
let mutex_a = Arc::new(Mutex::new(0_u32));
let mutex_b = mutex_a.clone();
let a = mutex_a.lock().unwrap();
let b = mutex_b.lock().unwrap();
println!("{}", *a + *b);C++ is from an era open source was not yet well established.