Graph and multithread

Hi,
I want to implement a graph with multithread. This is a possible beginning

I choose the type

Arc<Vec<RwLock<Arc<Node>>>

I would like to know if there is a better alternative.
I need the graph fully mutate graph and a node can exist independently.
A node have multple reader and one writer.
I didn't find a alternative to Rc<RefCell<Node>>

Thanks.

The analog to Rc<RefCell<Node>> is Arc<RwLock<Node>>, not RwLock<Arc<Node>>.

Single thread | Multi thread
--------------+--------------
Rc            | Arc
RefCell       | RwLock / Mutex

Thanks. I have this code

The borrow checker is just getting confused; the following works:

        let x = b.read().unwrap();
        let x = x.list[0].read().unwrap();
        println!(" {}", *x.data.read().unwrap());
1 Like

Thanks.