The Sync trait

The Sync trait, on the other hand, represents a type that can be shared between threads. This refers to actually sharing the variable without transferring its ownership to the new thread.

As with the Send trait, raw pointers and Rc are not Sync, but there is another family of types that implement not Send but not Sync. A Cell can be safely sent between threads, but it cannot be shared. Let's review how a Cell works.

A cell that can be found in the std::cell module is a container that will have some inner data. This data will be another type. Cells are used for interior mutability, but what is that? Interior mutability is the option to change the contents of a variable without it being mutable. This might sound counter-intuitive, ...

Get Rust High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.