From dd755df424bdff2cef6660dfd47f7160c2495ed8 Mon Sep 17 00:00:00 2001 From: Stefan Ring Date: Mon, 18 Apr 2011 21:05:48 +0200 Subject: [PATCH] * src/threads/posix/thread-posix.cpp, src/vm/jit/stacktrace.cpp: Sanitize the usage of condition variables. --- src/threads/posix/thread-posix.cpp | 10 +++++----- src/vm/jit/stacktrace.cpp | 7 ++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/threads/posix/thread-posix.cpp b/src/threads/posix/thread-posix.cpp index 820d7260e..45c71405f 100644 --- a/src/threads/posix/thread-posix.cpp +++ b/src/threads/posix/thread-posix.cpp @@ -1059,7 +1059,8 @@ static void threads_suspend_self() #endif // Release the suspension mutex and wait till we are resumed. - thread->suspendcond->wait(thread->suspendmutex); + while (thread->suspend_reason != SUSPEND_REASON_NONE) + thread->suspendcond->wait(thread->suspendmutex); #if defined(ENABLE_GC_CACAO) // XXX This is propably not ok! @@ -1079,7 +1080,7 @@ static void threads_suspend_self() /** * Suspend the passed thread. Execution of that thread stops until the thread - * is explicitly resumend again. + * is explicitly resumed again. * * @param thread The thread to be suspended. * @param reason Reason for suspending the given thread. @@ -1117,9 +1118,8 @@ bool threads_suspend_thread(threadobject *thread, int32_t reason) os::abort_errno("threads_suspend_thread: pthread_kill failed"); // Wait for the thread to acknowledge the suspension. - // XXX A possible optimization would be to not wait here, but you - // better think this through twice before trying it! - thread->suspendcond->wait(thread->suspendmutex); + while (!thread->suspended) + thread->suspendcond->wait(thread->suspendmutex); } return true; diff --git a/src/vm/jit/stacktrace.cpp b/src/vm/jit/stacktrace.cpp index ad3b43825..1593bd2fa 100644 --- a/src/vm/jit/stacktrace.cpp +++ b/src/vm/jit/stacktrace.cpp @@ -1,6 +1,6 @@ /* src/vm/jit/stacktrace.cpp - machine independent stacktrace system - Copyright (C) 1996-2005, 2006, 2007, 2008 + Copyright (C) 1996-2011 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO Copyright (C) 2009 Theobroma Systems Ltd. @@ -1402,7 +1402,8 @@ stacktrace_t* stacktrace_get_of_thread(threadobject* t) /* stacktrace_print_of_thread ************************************************** - Print the current stacktrace of the given thread. + Print the current stacktrace of the given thread. It will only work + for suspended threads. ARGUMENTS: t ... thread @@ -1422,7 +1423,7 @@ void stacktrace_print_of_thread(threadobject *t) sfi = t->_stackframeinfo; - if (sfi == NULL) { + if (!t->suspended || sfi == NULL) { puts("\t<>"); fflush(stdout); return; -- 2.25.1