From owner-p4-projects@FreeBSD.ORG Fri Dec 31 14:58:10 2004 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 30B5B16A4DB; Fri, 31 Dec 2004 14:58:10 +0000 (GMT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6460A16A4CF for ; Fri, 31 Dec 2004 14:58:09 +0000 (GMT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 344D743D2D for ; Fri, 31 Dec 2004 14:58:09 +0000 (GMT) (envelope-from davidxu@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id iBVEw9sM009300 for ; Fri, 31 Dec 2004 14:58:09 GMT (envelope-from davidxu@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id iBVEw8l8009297 for perforce@freebsd.org; Fri, 31 Dec 2004 14:58:08 GMT (envelope-from davidxu@freebsd.org) Date: Fri, 31 Dec 2004 14:58:08 GMT Message-Id: <200412311458.iBVEw8l8009297@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to davidxu@freebsd.org using -f From: David Xu To: Perforce Change Reviews Subject: PERFORCE change 67981 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 31 Dec 2004 14:58:11 -0000 http://perforce.freebsd.org/chv.cgi?CH=67981 Change 67981 by davidxu@davidxu_tiger on 2004/12/31 14:57:36 rework join related code. Affected files ... .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_exit.c#3 edit Differences ... ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_exit.c#3 (text+ko) ==== @@ -86,9 +86,10 @@ _pthread_exit(void *status) { struct pthread *curthread = _get_curthread(); + struct pthread *joiner; /* Check if this thread is already in the process of exiting: */ - if ((curthread->flags & THR_FLAGS_EXITING) != 0) { + if ((curthread->flags & THR_CANCEL_EXITING) != 0) { char msg[128]; snprintf(msg, sizeof(msg), "Thread %p has called " "pthread_exit() from a destructor. POSIX 1003.1 " @@ -101,9 +102,11 @@ * from joining to this thread. */ THR_LOCK(curthread); - curthread->flags |= THR_FLAGS_EXITING; + curthread->cancelflags |= THR_CANCEL_EXITING; THR_UNLOCK(curthread); + _thr_exit_cleanup(); + /* Save the return value: */ curthread->ret = status; while (curthread->cleanup != NULL) { @@ -117,23 +120,34 @@ /* Run the thread-specific data destructors: */ _thread_cleanupspecific(); } + if (!_thr_isthreaded()) exit(0); - THR_LOCK_ACQUIRE(curthread, &_thread_list_lock); - /* Use thread_list_lock */ + + THREAD_LIST_LOCK(curthread); + if ((joiner = curthread->joiner) != NULL) { + THR_THREAD_LOCK(curthread, joiner); + if (joiner->join_status.thread == curthread) { + joiner->join_status.thread = NULL; + joiner->join_status.ret = curthread->ret; + joiner->cycle++; + umtx_wake((struct umtx *)&joiner->cycle, 1); + } + THR_THREAD_UNLOCK(curthread, joiner); + } _thread_active_threads--; if (_thread_active_threads == 0) { - THR_LOCK_RELEASE(curthread, &_thread_list_lock); + THREAD_LIST_UNLOCK(curthread); exit(0); /* Never reach! */ } - THR_LOCK_RELEASE(curthread, &_thread_list_lock); - - THR_LOCK_SWITCH(curthread); - THR_SET_STATE(curthread, PS_DEAD); - _thr_sched_switch_unlocked(curthread); + curthread->tlflags |= TLFLAGS_GC_SAFE; + THR_GCLIST_ADD(curthread); + THR_LOCK(curthread); + curthread->state = PS_DEAD; + THR_UNLOCK(curthread); + THREAD_LIST_UNLOCK(curthread); + thr_exit(&curthread->isdead); + PANIC("thr_exit() returned"); /* Never reach! */ - - /* This point should not be reached. */ - PANIC("Dead thread has resumed"); }