You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ge...@apache.org on 2006/10/14 18:29:03 UTC
svn commit: r463973 -
/incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_basic.c
Author: geirm
Date: Sat Oct 14 09:29:00 2006
New Revision: 463973
URL: http://svn.apache.org/viewvc?view=rev&rev=463973
Log:
HARMONY-1816
There are several problems with non demon(those which vm should wait before destroing itself) threads counting in
drlvm:
1. Non daemon threads count being increased by the thread being run
This leads to the problem that main thread may finish w/o waiting for the child non-daemon thread;
2. Main thread waiting while number of non daemon threads will be equal to zero, while the main thread itself also
non daemon thread
(waiting method checks at enter that thread count should be <= 1, but waits on condition while count ==0)
Basically this causes vm to hang at shutdown if child thread works longer than main method.
Ubuntu 6 - testcase, smoke, c-unit, ~kernel
Modified:
incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_basic.c
Modified: incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_basic.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_basic.c?view=diff&rev=463973&r1=463972&r2=463973
==============================================================================
--- incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_basic.c (original)
+++ incubator/harmony/enhanced/drlvm/trunk/vm/thread/src/thread_java_basic.c Sat Oct 14 09:29:00 2006
@@ -86,10 +86,6 @@
jvmti_thread->jenv = jni_env;
jvmti_thread->daemon = data->daemon;
- if (!jvmti_thread->daemon) {
- increase_nondaemon_threads_count(native_thread);
- }
-
TRACE(("TM: Java thread started: id=%d OS_handle=%p", native_thread->thread_id, apr_os_thread_current()));
// Send Thread Start event.
@@ -165,6 +161,10 @@
data->tiEnv = attrs->jvmti_env;
data->tiProc = proc;
data->tiProcArgs = (void *)arg;
+
+ if (!data->daemon) {
+ increase_nondaemon_threads_count(hythread_self());
+ }
status = hythread_create(&tm_native_thread, (attrs->stacksize)?attrs->stacksize:1024000,
attrs->priority, 0, wrapper_proc, data);
@@ -635,10 +635,11 @@
return status;
}
- while (lib->nondaemon_thread_count) {
+ while ((!jvmti_thread->daemon && lib->nondaemon_thread_count > 1)
+ || (jvmti_thread->daemon && lib->nondaemon_thread_count > 0)) {
status = hycond_wait(lib->nondaemon_thread_cond, lib->TM_LOCK);
//check interruption and other problems
- TRACE(("TM wait for nondaemons notified, count: %d", nondaemon_thread_count));
+ TRACE(("TM wait for nondaemons notified, count: %d", lib->nondaemon_thread_count));
if(status != TM_ERROR_NONE) {
hymutex_unlock(lib->TM_LOCK);
return status;
@@ -715,11 +716,11 @@
return TM_ERROR_ILLEGAL_STATE;
}
- TRACE(("TM: nondaemons decreased, thread: %p count: %d", self, lib->nondaemon_thread_count));
+ TRACE(("TM: nondaemons decreased, thread: %p count: %d\n", self, lib->nondaemon_thread_count));
lib->nondaemon_thread_count--;
- if(lib->nondaemon_thread_count == 0) {
+ if(lib->nondaemon_thread_count <= 1) {
status = hycond_notify_all(lib->nondaemon_thread_cond);
- TRACE(("TM: nondaemons all dead, thread: %p count: %d", self, lib->nondaemon_thread_count));
+ TRACE(("TM: nondaemons all dead, thread: %p count: %d\n", self, lib->nondaemon_thread_count));
if (status != TM_ERROR_NONE){
hymutex_unlock(lib->TM_LOCK);
return status;