expression

Send without Sync: move a Cell

A Cell can be moved to another thread when its contained value is Send. The same Cell cannot be concurrently accessed through shared references. Transfer the whole value rather than share it. Expected stdout (not executed): 8 Common mistake: Treating Send and Sync as synonyms.

Formal Syntax & Structure

rust syntaxrust
Cell<T> can be Send when T: Send, but is not Sync

Working Example

Example Snippetrust
fn main() {    use std::cell::Cell;    let c = Cell::new(3u32);    let h = std::thread::spawn(move || { c.set(8); c.get() });    println!("{}", h.join().unwrap());}
Rust Reference