still deadlocking
This commit is contained in:
parent
c53edd921a
commit
e6d76ba37c
2 changed files with 9 additions and 5 deletions
|
@ -1,4 +1,7 @@
|
|||
use std::sync::{Arc, Mutex};
|
||||
use std::{
|
||||
rc::Rc,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use nebkor_maelstrom::{mk_payload, mk_stdin, Body, Message, Node, Runner};
|
||||
|
||||
|
@ -6,7 +9,7 @@ fn main() {
|
|||
let node = Counter;
|
||||
let node = Arc::new(Mutex::new(node));
|
||||
|
||||
let runner = Runner::new(node);
|
||||
let runner = Rc::new(Runner::new(node));
|
||||
|
||||
let (i, _, rx) = mk_stdin();
|
||||
|
||||
|
@ -33,7 +36,7 @@ const KEY: &str = "COUNTER";
|
|||
struct Counter;
|
||||
|
||||
impl Node for Counter {
|
||||
fn handle<'slf>(&'slf mut self, runner: &'slf Runner, req: Message) {
|
||||
fn handle<'slf>(&'slf mut self, runner: &'slf Rc<Runner>, req: Message) {
|
||||
let typ = req.body.typ.as_str();
|
||||
let frm = req.src.clone();
|
||||
let msg_id = req.body.msg_id.to_owned();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use std::{
|
||||
collections::HashMap,
|
||||
io::{BufRead, Stdout, Write},
|
||||
rc::Rc,
|
||||
sync::{
|
||||
atomic::{AtomicU64, AtomicUsize, Ordering},
|
||||
mpsc::{channel, Receiver, Sender},
|
||||
|
@ -26,7 +27,7 @@ static MSG_ID: AtomicU64 = AtomicU64::new(0);
|
|||
static OUTPUT: LazyLock<Stdout> = LazyLock::new(std::io::stdout);
|
||||
|
||||
pub trait Node {
|
||||
fn handle(&mut self, runner: &Runner, msg: Message);
|
||||
fn handle(&mut self, runner: &Rc<Runner>, msg: Message);
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -49,7 +50,7 @@ impl Runner {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn run(&self, input: Receiver<Message>, on_init: Option<OnInit>) {
|
||||
pub fn run(self: &Rc<Self>, input: Receiver<Message>, on_init: Option<OnInit>) {
|
||||
for msg in input.iter() {
|
||||
let typ = &msg.body.typ;
|
||||
if let "init" = typ.as_str() {
|
||||
|
|
Loading…
Reference in a new issue