Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::cell::RefCell;
- use std::rc::Rc;
- use std::sync::RwLock;
- use std::thread;
- use std::sync::Arc;
- use std::sync::Mutex;
- struct Graph {
- node_0: Rc<RefCell<Node0>>,
- node_1: Rc<RefCell<Node1>>
- }
- unsafe impl Send for Graph {}
- unsafe impl Sync for Graph {}
- #[derive(Debug)]
- struct Node0 {
- outgoing_ports: Vec<Rc<RefCell<OutgoingPort>>>
- }
- #[derive(Debug)]
- struct Node1 {
- incoming_port: Rc<RefCell<IncomingPort>>
- }
- #[derive(Debug)]
- struct OutgoingPort {
- destinations: Vec<Rc<RefCell<IncomingPort>>>
- }
- #[derive(Debug)]
- struct IncomingPort {
- sources: Vec<Rc<RefCell<OutgoingPort>>>
- }
- fn main() {
- println!("Hello, world!");
- let p0 = Rc::new(RefCell::new(OutgoingPort {destinations: vec!()}));
- let n0 = Rc::new(RefCell::new(Node0 { outgoing_ports: vec!(p0.clone()) }));
- let p1 = Rc::new(RefCell::new(IncomingPort { sources: vec!()}));
- let n1 = Rc::new(RefCell::new(Node1 { incoming_port: p1.clone()} ));
- {
- let mut p0_mut = p0.borrow_mut();
- p0_mut.destinations.push(p1.clone());
- }
- {
- let mut p1_mut = p1.borrow_mut();
- p1_mut.sources.push(p0.clone())
- }
- let lock = Arc::new(RwLock::new(Graph {node_0: n0, node_1: n1}));
- thread::spawn(move || {
- do_stuff(lock.clone());
- });
- }
- fn do_stuff(g: Arc<RwLock<Graph>>) {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement