News for hackers. Stuff that matters.
Re:Rust Ownership Rules by clktmr on Monday March 02, 2020 @09:39AM (#22464758)
Some commenters mention Rust has compile-time data-race checking. Is this correct? From what I did understand it will only enforce a mutex to be locked before you can access specific data. However if there is no mutex, data-races won't be detected at compile time?
Re:Rust Ownership Rules by steveklabnik on Monday March 02, 2020 @09:39AM (#22464760)
It is correct. Rust prevents all data races at compile time, unless you write incorrect unsafe code. This is why people try to write as little unsafe as possible. This has nothing to do with Mutexes; mutexes are provided by the standard library and the language knows nothing specific about them.
Re:Rust Ownership Rules by clktmr on Monday March 02, 2020 @10:06AM (#22464972)
I understand. It is actually kind of easy to comprehend by remembering the borrow checker will only allow one single mutable reference at a time.
Re:Rust Ownership Rules by yangl1996 on Monday March 02, 2020 @09:40AM (#22464767)
Rust compiler forbids multiple threads to access the same memory location not protected by a Mutex.
Re:Rust Ownership Rules by hexaga on Monday March 02, 2020 @09:49AM (#22464832)
That is, only when said memory location is accessed mutably. Immutable references are perfectly ok to follow concurrently.