Ben Chuanlong Du's Blog

It is never too late to learn.

Send and Sync in Rust

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

Tips and Traps

  1. Send and Sync are 2 thread-safty related marker traits in Rust.

  2. A type is Send if and only if it can be transferred across thread boundaries. A type is Sync if and only if &T is Send.

  3. A MutexGuard is not Send but is Sync. A Rc is neither Send not Sync. A Cell / RefCell is Send (if its inner type is Send) but is never Sync (no matter what its inner type is).

References

Crust of Rust: Send, Sync, and their implementors https://www.youtube.com/watch?v=yOezcP-XaIw

Rustonomicon - Send and Sync https://doc.rust-lang.org/nomicon/send-and-sync.html?highlight=send%20sync#send-and-sync

Comments