From d690d235a7579673bba1df7a20fdec7648e1bbc4 Mon Sep 17 00:00:00 2001 From: honzuki <22032642+honzuki@users.noreply.github.com> Date: Tue, 31 Jan 2023 21:41:42 +0200 Subject: [PATCH] Fix potential deadlock in the executor Remove the usage of blocking api inside 'spawn' and 'wake' --- examples/02_04_executor/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/02_04_executor/src/lib.rs b/examples/02_04_executor/src/lib.rs index 13dadb72..2cf02cfd 100644 --- a/examples/02_04_executor/src/lib.rs +++ b/examples/02_04_executor/src/lib.rs @@ -61,7 +61,7 @@ impl Spawner { future: Mutex::new(Some(future)), task_sender: self.task_sender.clone(), }); - self.task_sender.send(task).expect("too many tasks queued"); + self.task_sender.try_send(task).expect("too many tasks queued"); } } // ANCHOR_END: spawn_fn @@ -74,7 +74,7 @@ impl ArcWake for Task { let cloned = arc_self.clone(); arc_self .task_sender - .send(cloned) + .try_send(cloned) .expect("too many tasks queued"); } }