
Understand it
Send means a value can be moved to another thread; Sync means &T can be shared with one. Both are inferred from a type's fields, so you rarely write them — but they are why Rc is rejected at compile time while Arc is accepted, and why a whole class of race is a type error.
Send and Sync are marker traits describing safe movement and sharing across threads. A Send value may transfer ownership to another thread. A Sync type may be accessed through shared references from multiple threads; equivalently, &T can be Send when T is Sync. These properties are usually derived automatically from fields, so the type composition communicates the safety constraint.
Rc<T> changes a non-atomic reference count, so it is unsuitable for sharing between threads. Arc<T> uses an atomic count, but that does not make arbitrary inner mutation safe. If workers must change the contained value, combine it with a suitable synchronization primitive such as Mutex<T>, or use atomics for a very narrow operation. The compiler rejecting Rc in a spawned thread is evidence of a missing thread-safety guarantee, not an invitation to add unsafe impl casually.
Test this by capturing an Rc<String> in a thread closure and reading the diagnostic. Replace it with Arc<String> for read-only sharing. Then try to mutate a shared counter and choose Arc<Mutex<i32>> or Arc<AtomicUsize> based on the operation. Ask separately whether ownership crosses threads and whether references may be shared. Send and Sync answer those two different questions; they do not promise freedom from deadlocks, starvation, or application-level ordering mistakes.
A value can be Send without being Sync, so moving it exclusively to another thread may work even when simultaneous shared references would not. Check the precise compiler bound at the thread or library boundary. This tells you whether to change ownership, add synchronization, or redesign the data flow. Never assert these marker traits manually unless you can prove the unsafe contract for every field and operation.
Read the code
fn spawn_it<F>(job: F) -> std::thread::JoinHandle<()>
where
F: FnOnce() + Send + 'static,
{
std::thread::spawn(job)
}
// Arc<i32> is Send + Sync, so this is accepted.
let value = std::sync::Arc::new(7);
spawn_it(move || println!("{value}")).join().unwrap();The bound is what the thread API asks for, spelled out.
Practice starter
use std::cell::RefCell;
use std::thread;
let cell = RefCell::new(0);
thread::scope(|scope| {
scope.spawn(|| {
*cell.borrow_mut() += 1;
});
});Try it
Name why one shared pointer crosses threads and the other does not.
What success looks like: You can explain the difference in terms of the count, not the API.
Check your understanding
What stops that closure borrowing the cell on another thread?
Reveal the answer
- RefCell is not Sync, and its runtime check is not atomic
- A closure is not allowed to capture a cell type
- borrow_mut needs an unsafe block to compile
The closure captures &RefCell<i32>, and &T is Send only when T is Sync. RefCell's borrow flag is not synchronised, so the shared borrow is rejected; moving the cell instead compiles, because RefCell<i32> is Send.
Go deeper
Common misconception: “A type that is Send can also be shared between threads.”
Send and Sync are separate. RefCell<i32> can move to a thread because it is Send, but borrowing it from one needs Sync: T is Sync exactly when &T is Send.
- Read the bound:
spawn_itrequiresF: FnOnce() + Send + 'static, so everything the closure captures must beSendand must not borrow short-lived data. - Check the capture:
moveputs theArc<i32>in the closure.Arc<i32>isSendbecausei32isSend + Sync, so the bound holds andjoinwaits for the printed 7. - Swap the pointer: Replace the
Arcwithstd::rc::Rc::new(7). The closure is no longerSend, so thespawn_itcall fails with E0277.
Transfer challenge: Add move to the practice's inner closure and predict whether it compiles. Then explain why moving the RefCell is accepted when sharing it through thread::scope is not.
Connections
- Shared State: Mutex, RwLock, and Arc
- Futures: async fn, await, and laziness
Learn this lesson with AI
Paste this into Claude, Codex, Cursor or another agent connected to Crabrix Academy. It contains only this lesson’s public details.
I'm learning Rust with Crabrix Academy. Teach me this lesson with the Crabrix Academy tools. Lesson: Send & Sync (courseId "concurrency", lessonId "send-sync") Link: https://crabrix.com/learn/concurrency/send-sync/ Goal: T is Sync exactly when &T is Send. Practice: open the starter in the Crabrix Playground (https://crabrix.com/playground/?lesson=concurrency/send-sync) and I will write the code there. Explain it step by step for my level, let me write the code myself, give hints before any solution, and do not mark anything as passed: only Crabrix checks do that.