From 7c64e578af7322c4e1a01a1d584fa0d04ab7fbe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Thu, 12 Jan 2023 17:06:46 +0100 Subject: [PATCH] rs/AsyncCallback: Join thread before creating new one --- test/Rust/src/concurrent/AsyncCallback.lf | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/Rust/src/concurrent/AsyncCallback.lf b/test/Rust/src/concurrent/AsyncCallback.lf index eb236db42c..053d8ae33d 100644 --- a/test/Rust/src/concurrent/AsyncCallback.lf +++ b/test/Rust/src/concurrent/AsyncCallback.lf @@ -4,7 +4,7 @@ target Rust { cargo-features: ["cli"] } -main reactor AsyncCallback(period: time(1 msec)) { +main reactor AsyncCallback(period: time(10 msec)) { preamble {= use std::thread; =} timer t(0, period) @@ -19,6 +19,9 @@ main reactor AsyncCallback(period: time(1 msec)) { reaction(t) -> act {= let act = act.clone(); let period = self.period; + if let Some(old_thread) = self.thread.take() { + old_thread.join().ok(); + } // start new thread let new_thread = ctx.spawn_physical_thread(move |ctx| { // Simulate time passing before a callback occurs @@ -31,9 +34,7 @@ main reactor AsyncCallback(period: time(1 msec)) { ctx.schedule_physical(&act, Asap).ok(); }); - if let Some(old_thread) = self.thread.replace(new_thread) { - old_thread.join().ok(); - } + self.thread.replace(new_thread); =} reaction(act) {=