From 0a5603cb58bdc66ad6b6a030e4e98ebeb3c13721 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sat, 3 Mar 2012 20:50:11 -0800 Subject: rt: Make linked failure less prone to deadlock Still a mess. --- src/rt/rust_task_thread.cpp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'src/rt/rust_task_thread.cpp') diff --git a/src/rt/rust_task_thread.cpp b/src/rt/rust_task_thread.cpp index cf16f209a4e..e108a21f3a9 100644 --- a/src/rt/rust_task_thread.cpp +++ b/src/rt/rust_task_thread.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "rust_internal.h" #include "rust_util.h" #include "globals.h" @@ -95,19 +96,27 @@ rust_task_thread::fail() { void rust_task_thread::kill_all_tasks() { - I(this, !lock.lock_held_by_current_thread()); - scoped_lock with(lock); + std::vector all_tasks; - for (size_t i = 0; i < running_tasks.length(); i++) { - // We don't want the failure of these tasks to propagate back - // to the kernel again since we're already failing everything - running_tasks[i]->unsupervise(); - running_tasks[i]->kill(); + { + scoped_lock with(lock); + + for (size_t i = 0; i < running_tasks.length(); i++) { + all_tasks.push_back(running_tasks[i]); + } + + for (size_t i = 0; i < blocked_tasks.length(); i++) { + all_tasks.push_back(blocked_tasks[i]); + } } - for (size_t i = 0; i < blocked_tasks.length(); i++) { - blocked_tasks[i]->unsupervise(); - blocked_tasks[i]->kill(); + while (!all_tasks.empty()) { + rust_task *task = all_tasks.back(); + all_tasks.pop_back(); + // We don't want the failure of these tasks to propagate back + // to the kernel again since we're already failing everything + task->unsupervise(); + task->kill(); } } -- cgit 1.4.1-3-g733a5