here is my code. the structurs should be event base and also multithreaded. any design idea ?
use std::sync::{Arc,Mutex};
trait dd{
fn notify(&mut self);
}
struct a {
write: Vec<Arc<Mutex<dyn dd>>>// spin::Mutex
}
impl dd for a{
fn notify(&mut self){
for notif in write{
(*self.notif.lock()).notify();// spin::Mutex
}
}
}
struct conn{
should_notify: Vec<Arc<Mutex<dyn dd>>>// spin::Mutex
}
impl dd for a{
fn notify(&mut self){
for notif in should_notify{
(*self.notif.lock()).notify();// spin::Mutex
}
}
}
fn main() {
let mut a = a{write: Vec::new()};
let mut conn = Arc::from(Mutex::from(conn{should_notify: Vec::new()}));
a.write.push(conn.clone());
std::thread::spawn(||{
loop{
(*conn.lock()).notify();
std::thread::sleep(std::time::Duration::frim_millis(10));
}
});
}