No, at least not directly inside. To understand why, you need to understand that the real difference between immutable and mutable is whether you have exclusive access to the thing. The entire purpose of a
RwLock is to allow you to obtain exclusive (i.e. mutable) access to the thing behind the lock, even though the lock is shared (i.e. you don't have exclusive access to the lock itself).
Arc<T> can be cloned, giving out multiple handles to the same thing. So, even if you have exclusive access to the
Arc<T>, you only have shared access to the
T, as it might not be the only arc.
So in short:
Arc<T> gives shared-only access to
Mutex<Arc<T>> gives shared-only access to
What does make sense is to have
Mutex<HashMap<String, Arc<Value>>>. This makes sense because you can:
- Lock the mutex.
- Access some key in the map, calling
clone on the
- Unlock the mutex.
- Continue to access the value in the map through your clone of the
Of course, the value stored inside the
HashMap becomes immutable if you do this, since there may be other arcs to the value. However to change it, you can replace the
Arc with a new
Arc, letting anyone still looking at the value continue to see the old value, but making any future accesses see the new value.