Back to sync

For sync to occur, we cannot have any type that uses interior mutability (which also includes some of the primitive types).

When it comes to sharing across threads, Rust uses Arc<T>. This is a wrapper type that implements send and sync if the following condition is met: T must implement both send and sync. RefCell uses interior mutability, so Arc<RefCell<T>> won't implement sync, which also means send can't be used—therefore RefCell can't be passed around threads.

Using send and sync provides the strong guarantees of safety Rust relies upon to ensure the code is rock solid when using a threading system.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset