Start with the idea
Arc<T> is Rc with an atomic count so it can cross threads. Mutex<T> holds the data itself rather than guarding it by convention, so the only way to reach the value is to lock — and the guard unlocks when it drops, which means a forgotten unlock is not a bug you can write.
Arc<T> is an atomically reference-counted owner that can be cloned across threads when the contained type permits it. Mutex<T> protects mutable data with a lock. Together, Arc<Mutex<T>> lets workers own handles to one allocation while only one guard at a time accesses the protected value. Cloning an Arc clones a handle, not the inner data. The guard from lock() releases the lock when it leaves scope.
In a counter example, each worker clones the Arc, locks the mutex, increments the count, and drops the guard.
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.