Systems Design Questions · 18 min · free with an account

Send and Sync

Lesson preview · about 30%

Two marker traits decide what may cross a thread boundary.

Core idea

T is Sync exactly when &T is Send.

Start with the idea

Send means a value may be moved to another thread; Sync means &T may be shared with one. They are inferred from a type's fields, which is why Rc is rejected at compile time while Arc is accepted — the difference is an atomic count, and the type system knows it.

Send allows ownership of a value to cross a thread boundary. Sync allows shared references to the value to be used from multiple threads; formally, &T is Send when T is Sync. These are marker traits, usually inferred from the fields of a type. A type may satisfy one but not the other. The distinction is about transfer versus shared access, so answer those as separate questions rather than saying a type is simply 'thread safe'.

Keep learning, for free

The rest of this lesson is waiting for you.

Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.

No payment details. Your account opens the complete Academy.

← All lessons in Rust Interview Prep