Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

rs/AsyncCallback: Join thread before creating new one #1542

Merged
merged 1 commit into from
Jan 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions test/Rust/src/concurrent/AsyncCallback.lf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ target Rust {
cargo-features: ["cli"]
}

main reactor AsyncCallback(period: time(1 msec)) {
main reactor AsyncCallback(period: time(10 msec)) {
lhstrh marked this conversation as resolved.
Show resolved Hide resolved
preamble {= use std::thread; =}

timer t(0, period)
Expand All @@ -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
Expand All @@ -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) {=
Expand Down