2007-11-15 Dick Porter <dick@ximian.com>
authorDick Porter <dick@acm.org>
Thu, 15 Nov 2007 20:03:27 +0000 (20:03 -0000)
committerDick Porter <dick@acm.org>
Thu, 15 Nov 2007 20:03:27 +0000 (20:03 -0000)
* threads.c (ves_icall_System_Threading_Thread_Join_internal):
When joining a thread, it's the thread that's calling Join that
gets WaitSleepJoin state not the target.  Fixes the standalone
test case in bug 334740, and hopefully the whole bug too.

svn path=/trunk/mono/; revision=89699

mono/metadata/ChangeLog
mono/metadata/threads.c

index e19399b9f6eb8ec76fc6e458458f5f2ca26ca4bd..922411863baca4f45afd3d669b3078666c6dccbb 100644 (file)
@@ -1,3 +1,10 @@
+2007-11-15  Dick Porter  <dick@ximian.com>
+
+       * threads.c (ves_icall_System_Threading_Thread_Join_internal):
+       When joining a thread, it's the thread that's calling Join that
+       gets WaitSleepJoin state not the target.  Fixes the standalone
+       test case in bug 334740, and hopefully the whole bug too.
+
 2007-11-15  Dick Porter  <dick@ximian.com>
 
        * process.c: Read file version info from the files pointed at by
index 8100f42e6f363d3c587ef56b6b74d72567d994f2..a2a984e3852e6b95e25dc293e0459e6f49be9dc4 100644 (file)
@@ -1165,6 +1165,7 @@ mono_thread_current (void)
 gboolean ves_icall_System_Threading_Thread_Join_internal(MonoThread *this,
                                                         int ms, HANDLE thread)
 {
+       MonoThread *cur_thread = mono_thread_current ();
        gboolean ret;
        
        MONO_ARCH_SAVE_REGS;
@@ -1179,8 +1180,6 @@ gboolean ves_icall_System_Threading_Thread_Join_internal(MonoThread *this,
                mono_raise_exception (mono_get_exception_thread_state ("Thread has not been started."));
                return FALSE;
        }
-       
-       this->state |= ThreadState_WaitSleepJoin;
 
        LeaveCriticalSection (this->synch_cs);
 
@@ -1189,9 +1188,11 @@ gboolean ves_icall_System_Threading_Thread_Join_internal(MonoThread *this,
        }
        THREAD_DEBUG (g_message ("%s: joining thread handle %p, %d ms", __func__, thread, ms));
        
+       mono_thread_set_state (cur_thread, ThreadState_WaitSleepJoin);
+
        ret=WaitForSingleObjectEx (thread, ms, TRUE);
 
-       mono_thread_clr_state (this, ThreadState_WaitSleepJoin);
+       mono_thread_clr_state (cur_thread, ThreadState_WaitSleepJoin);
        
        if(ret==WAIT_OBJECT_0) {
                THREAD_DEBUG (g_message ("%s: join successful", __func__));