* src/threads/posix/thread-posix.cpp, src/vm/jit/stacktrace.cpp: Sanitize
authorStefan Ring <stefan@complang.tuwien.ac.at>
Mon, 18 Apr 2011 19:05:48 +0000 (21:05 +0200)
committerStefan Ring <stefan@complang.tuwien.ac.at>
Mon, 18 Apr 2011 19:05:48 +0000 (21:05 +0200)
the usage of condition variables.

src/threads/posix/thread-posix.cpp
src/vm/jit/stacktrace.cpp

index 820d7260ee470ec645ce03c82945bd3a3a9bae93..45c71405f933c7f2bf054b36a8c6d03d54d42ef7 100644 (file)
@@ -1059,7 +1059,8 @@ static void threads_suspend_self()
 #endif
 
        // Release the suspension mutex and wait till we are resumed.
 #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!
 
 #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
 
 /**
  * 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.
  *
  * @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.
                        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;
        }
 
        return true;
index ad3b438255da749d1107fa5f5e974d6e5e9e59dd..1593bd2fa4ba22a8b67b26f37c5060713ead3818 100644 (file)
@@ -1,6 +1,6 @@
 /* src/vm/jit/stacktrace.cpp - machine independent stacktrace system
 
 /* 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.
 
    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 **************************************************
 
 
 /* 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
 
    ARGUMENTS:
        t ... thread
@@ -1422,7 +1423,7 @@ void stacktrace_print_of_thread(threadobject *t)
 
        sfi = t->_stackframeinfo;
        
 
        sfi = t->_stackframeinfo;
        
-       if (sfi == NULL) {
+       if (!t->suspended || sfi == NULL) {
                puts("\t<<No stacktrace available>>");
                fflush(stdout);
                return;
                puts("\t<<No stacktrace available>>");
                fflush(stdout);
                return;