From b404c6f2d0b5be2ade7e3583a22c84b79f4cb1f8 Mon Sep 17 00:00:00 2001 From: Salikh Zakirov Date: Wed, 28 Feb 2007 21:09:29 +0300 Subject: [PATCH] Limited Thread.stop() fix for stopping waiting threads --- vm/thread/src/thread_java_basic.c | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-) diff --git a/vm/thread/src/thread_java_basic.c b/vm/thread/src/thread_java_basic.c index 05a35b1..832fcdd 100644 --- a/vm/thread/src/thread_java_basic.c +++ b/vm/thread/src/thread_java_basic.c @@ -416,7 +416,24 @@ void stop_callback(void) { tm_native_thread->suspend_request = 0; hysem_post(tm_native_thread->resume_event); + // Does not return if the exception could be thrown straight away jthread_throw_exception_object(excn); + + // getting here means top stack frame is non-unwindable. + + if (tm_native_thread->state & + (TM_THREAD_STATE_SLEEPING | TM_THREAD_STATE_WAITING_WITH_TIMEOUT + | TM_THREAD_STATE_WAITING | TM_THREAD_STATE_IN_MONITOR_WAIT + | TM_THREAD_STATE_WAITING_INDEFINITELY | TM_THREAD_STATE_PARKED)) { + // This is needed for correct stopping of a thread blocked on monitor_wait. + // The thread needs some flag to exit its waiting loop. + // We piggy-back on interrupted status. A correct exception from TLS + // will be thrown because the check of exception status on leaving + // JNI frame comes before checking return status in Object.wait(). + // Interrupted status will be cleared by function returning TM_ERROR_INTERRUPT. + // (though, in case of parked thread, it will not be cleared) + hythread_interrupt(tm_native_thread); + } } /** -- 1.5.0.32.g0dacb