Rust Send and Sync marker traits explained
WHAT IT TESTS: understanding of compile-time thread-safety guarantees. OUTLINE: Send means a value can move across threads, Sync means a reference can be shared; Rc uses non-atomic refcounts, Arc uses atomic ones. RED FLAG: confusing the two traits.
WHAT IT TESTS: whether you grasp how Rust encodes thread safety in the type system. ANSWER OUTLINE: Send means ownership of a value can be transferred to another thread; Sync means &T can be shared across threads (equivalently T: Sync iff &T: Send). Rc's reference count is incremented non-atomically, so concurrent clones could race and corrupt it, making it neither. Arc uses atomic counters, so it is both when T is. RED FLAG: claiming Sync means a type is internally locked, or treating Send and Sync as interchangeable.
Read the original → interview
- #rust
- #concurrency
- #send-sync
- #memory-safety
- #traits
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.