Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: threads.c 7984 2007-05-30 20:30:00Z twisti $
+ $Id: threads.c 8003 2007-06-03 18:42:09Z twisti $
*/
}
+/* threads_mutex_join_lock *****************************************************
+
+ Enter the join mutex.
+
+*******************************************************************************/
+
+void threads_mutex_join_lock(void)
+{
+ if (pthread_mutex_lock(&mutex_join) != 0)
+ vm_abort("threads_mutex_join_lock: pthread_mutex_lock failed: %s",
+ strerror(errno));
+}
+
+
+/* threads_mutex_join_unlock ***************************************************
+
+ Leave the join mutex.
+
+*******************************************************************************/
+
+void threads_mutex_join_unlock(void)
+{
+ if (pthread_mutex_unlock(&mutex_join) != 0)
+ vm_abort("threads_mutex_join_unlock: pthread_mutex_unlock failed: %s",
+ strerror(errno));
+}
+
+
/* threads_init ****************************************************************
Initializes the threads required by the JVM: main, finalizer.
java_lang_VMThread *vmt;
#endif
+ /* Enter the join-mutex, so if the main-thread is currently
+ waiting to join all threads, the number of non-daemon threads
+ is correct. */
+
+ threads_mutex_join_lock();
+
/* create internal thread data-structure */
thread = threads_thread_new();
+ /* thread is a Java thread and running */
+
+ thread->flags = THREAD_FLAG_JAVA;
+
+ if (isdaemon)
+ thread->flags |= THREAD_FLAG_DAEMON;
+
+ /* The thread is flagged and (non-)daemon thread, we can leave the
+ mutex. */
+
+ threads_mutex_join_unlock();
+
/* create a java.lang.Thread object */
t = (java_lang_Thread *) builtin_new(class_java_lang_Thread);
+ /* XXX memory leak!!! */
if (t == NULL)
return false;
thread->object = t;
- /* thread is a Java thread and running */
-
- thread->flags = THREAD_FLAG_JAVA;
-
- if (isdaemon)
- thread->flags |= THREAD_FLAG_DAEMON;
-
/* thread is completely initialized */
threads_thread_state_runnable(thread);
vmt = (java_lang_VMThread *) builtin_new(class_java_lang_VMThread);
+ /* XXX memory leak!!! */
if (vmt == NULL)
return false;
}
#endif
- /* signal that this thread has finished */
+ /* Enter the join-mutex before calling threads_thread_free, so
+ threads_join_all_threads gets the correct number of non-daemon
+ threads. */
- pthread_mutex_lock(&mutex_join);
- pthread_cond_signal(&cond_join);
- pthread_mutex_unlock(&mutex_join);
+ threads_mutex_join_lock();
/* free the vm internal thread object */
threads_thread_free(thread);
+ /* Signal that this thread has finished and leave the mutex. */
+
+ pthread_cond_signal(&cond_join);
+ threads_mutex_join_unlock();
+
return true;
}
/* enter join mutex */
- pthread_mutex_lock(&mutex_join);
+ threads_mutex_join_lock();
/* Wait for condition as long as we have non-daemon threads. We
compare against 1 because the current (main thread) is also a
/* leave join mutex */
- pthread_mutex_unlock(&mutex_join);
+ threads_mutex_join_unlock();
}
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: threads-common.c 7998 2007-06-01 00:29:51Z twisti $
+ $Id: threads-common.c 8003 2007-06-03 18:42:09Z twisti $
*/
java_lang_VMThread *vmt;
#endif
+ /* Enter the join-mutex, so if the main-thread is currently
+ waiting to join all threads, the number of non-daemon threads
+ is correct. */
+
+ threads_mutex_join_lock();
+
/* create internal thread data-structure */
t = threads_thread_new();
+ t->flags = THREAD_FLAG_INTERNAL | THREAD_FLAG_DAEMON;
+
+ /* The thread is flagged as (non-)daemon thread, we can leave the
+ mutex. */
+
+ threads_mutex_join_unlock();
+
/* create the java thread object */
object = (java_lang_Thread *) builtin_new(class_java_lang_Thread);
+ /* XXX memory leak!!! */
if (object == NULL)
return false;
#if defined(WITH_CLASSPATH_GNU)
vmt = (java_lang_VMThread *) builtin_new(class_java_lang_VMThread);
+ /* XXX memory leak!!! */
if (vmt == NULL)
return false;
t->object = object;
- t->flags = THREAD_FLAG_INTERNAL | THREAD_FLAG_DAEMON;
-
/* set java.lang.Thread fields */
#if defined(WITH_CLASSPATH_GNU)
{
threadobject *thread;
- /* create internal thread data-structure */
+ /* Enter the join-mutex, so if the main-thread is currently
+ waiting to join all threads, the number of non-daemon threads
+ is correct. */
- thread = threads_thread_new();
+ threads_mutex_join_lock();
- /* link the two objects together */
+ /* create internal thread data-structure */
- thread->object = object;
+ thread = threads_thread_new();
/* this is a normal Java thread */
thread->flags |= THREAD_FLAG_DAEMON;
#endif
+ /* The thread is flagged and (non-)daemon thread, we can leave the
+ mutex. */
+
+ threads_mutex_join_unlock();
+
+ /* link the two objects together */
+
+ thread->object = object;
+
#if defined(WITH_CLASSPATH_GNU)
assert(object->vmThread);
assert(object->vmThread->vmdata == NULL);
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: threads-common.h 7998 2007-06-01 00:29:51Z twisti $
+ $Id: threads-common.h 8003 2007-06-03 18:42:09Z twisti $
*/
void threads_list_lock(void);
void threads_list_unlock(void);
+void threads_mutex_join_lock(void);
+void threads_mutex_join_unlock(void);
+
void threads_set_current_threadobject(threadobject *thread);
void threads_impl_thread_new(threadobject *t);
void threads_impl_thread_free(threadobject *t);