Graph and multithread


#1

Hi,
I want to implement a graph with multithread. This is a possible beginning
https://play.rust-lang.org/?gist=9d14fbfae0be463a20183eadd71d3b1c&version=nightly&backtrace=0
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.


#2

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

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

#3

Thanks. I have this code
https://play.rust-lang.org/?gist=9a2b519c12000e5db8ffcc328a8c00ac&version=stable&backtrace=0


#4

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());

#5

Thanks.