There is a large array arr of structures A containing references to nested structures B. There is one mutex allowing write access to the array arr. How to describe references to B so that if there is a write reference to arr, the thread would have write access to the nested structures of B as well?
There is an option:
struct A {
b_ref: Arc<Mutex<B>> // Reference to B
}
struct MyArray {
arr: Vec<A>, // Array of structures A
mutex: Mutex<()> // Shared mutex for accessing array arr
}
But with a large arr, having many mutexes is inefficient
There is also an option here: Nested struct with reference But it uses unsafe