Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Rust enforces exclusive access to a variable before it allows mutation.

But there are plenty of data types like smart pointers, where multiple copies of the original smart pointer points to the same underlying data.

In the eyes of the compiler, these are different variables, and can be manipulated independently.

When writing said smart pointer, however, Rust won't allow you to share data between copies unless you explicitly ask for disabling some of the compile checks. When you do this, you need to manually ensure (thread) safety. And this is where locks and other concurrency primitives generally come in handy.



Ah so locks come into play when you deliberately disable compile checks?


Not exactly. Disabling the borrow checker is an internal implementation detail of the locking types, but it happens opaquely to the code using the locks.

The locking types make assurances with regards to the lifetimes of their parameters / contents / return values and these are still enforced by the compiler.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: