--- C:\Documents and Settings\ebrevnov\Local Settings\Temp\2\thread_native_basic.c-revBASE.svn000.tmp.c 2006-12-06 12:55:20.000000000 +-0600 +++ C:\.usr\bev\harmony-drlvm-shutdown\trunk\vm\thread\src\thread_native_basic.c 2006-12-06 12:53:47.000000000 +-0600 @@ -273,18 +273,27 @@ void VMCALL hythread_detach(hythread_t thread) { - // Acquire global TM lock to prevent concurrent acccess to thread list IDATA status; - - assert(thread == tm_self_tls); + + if (thread == NULL) { + thread = hythread_self(); + } + + // Acquire global TM lock to prevent concurrent acccess to thread list status = hythread_global_lock(NULL); assert (status == TM_ERROR_NONE); - thread_set_self(NULL); - fast_thread_array[thread->thread_id] = NULL; - - thread->prev->next = thread->next; - thread->next->prev = thread->prev; - thread->group->threads_count--; - + // No actions required in case the specified thread is detached already. + if (thread->group != NULL) { + assert(thread == tm_self_tls); + + thread_set_self(NULL); + fast_thread_array[thread->thread_id] = NULL; + + thread->prev->next = thread->next; + thread->next->prev = thread->prev; + thread->group->threads_count--; + thread->group = NULL; + } + hythread_global_unlock(NULL); assert(status == TM_ERROR_NONE); }