Hacker News new | ask | show | jobs
by notfed 290 days ago
It's almost as if this post was written in direct response to TFA to brag about how far ahead C# has been for over a decade.
1 comments

The C# is basically showing the Monitor pattern, which was also a thing in Java last century.

The Rust Mutex is an Owning Mutex which is a different feature whose benefit is that you need to take the lock to get at the protected data, which averts situations where you forget in some code but not others and create sync problems - in C# those may go undetected or may trigger a runtime exception, no guarantees.

But perhaps even more importantly, and why other languages which could do the Owning Mutex often do not, Rust's borrow checking means the compiler will spot mistakes where you gave back the lock but retained access to the data it was protecting. So you're protected both ways - you can't forget to take the lock, and you also can't give it back without also giving back the access.

Monitors prevent only the second (and only partly), an Owning Mutex in most languages prevents the first, but Rust prevents both.