2 ms·
> They are error prone, you can forget to unlock That's not a problem with mutexes but with resource management in some languages. In Rust mutexes use RAII and
by pkolaczk 3y ago
> They are error prone, you can forget to unlock
That's not a problem with mutexes but with resource management in some languages. In Rust mutexes use RAII and unlock automatically - you cannot accidentally forget to unlock.
- veber-alex 3y agoYes but it is very easy to hold mutexes locked longer than needed because you usually don't think about when stuff is dropped in Rust, you just let it go out of scope. I have gotten really annoying deadlocks because of this in the past.
- pkolaczk 3y agoFair point, but in order to make a deadlock, you need a reference back to the object that holds the lock. And back references in Rust are hard to make. Most of the time if you unlock too late, you get a performance problem, not a deadlock.