diff --git a/src/rt/rust_task.cpp b/src/rt/rust_task.cpp index 952e5c8c47d0..92637ace632e 100644 --- a/src/rt/rust_task.cpp +++ b/src/rt/rust_task.cpp @@ -155,9 +155,12 @@ cleanup_task(cleanup_args *args) { task->die(); - if (task->killed && !threw_exception) { - LOG(task, task, "Task killed during termination"); - threw_exception = true; + { + scoped_lock with(task->kill_lock); + if (task->killed && !threw_exception) { + LOG(task, task, "Task killed during termination"); + threw_exception = true; + } } task->notify(!threw_exception); @@ -244,6 +247,7 @@ void rust_task::start() bool rust_task::must_fail_from_being_killed() { + scoped_lock with(kill_lock); return killed && !reentered_rust_stack; } @@ -275,7 +279,10 @@ rust_task::kill() { // If you want to fail yourself you do self->fail(). LOG(this, task, "killing task %s @0x%" PRIxPTR, name, this); // When the task next goes to yield or resume it will fail - killed = true; + { + scoped_lock with(kill_lock); + killed = true; + } // Unblock the task so it can unwind. unblock(); diff --git a/src/rt/rust_task.h b/src/rt/rust_task.h index 28446d9048ab..300c1df133ca 100644 --- a/src/rt/rust_task.h +++ b/src/rt/rust_task.h @@ -107,6 +107,8 @@ rust_task : public kernel_owned, rust_cond private: + // Protects the killed flag + lock_and_signal kill_lock; // Indicates that the task was killed and needs to unwind bool killed; // Indicates that we've called back into Rust from C