Fix 5771/library: in pthread_exit(), delay the call to _sem_post() that
authorguenther <guenther@openbsd.org>
Thu, 14 Aug 2008 05:20:44 +0000 (05:20 +0000)
committerguenther <guenther@openbsd.org>
Thu, 14 Aug 2008 05:20:44 +0000 (05:20 +0000)
unblocks the pthread_join() for this thread until the exiting thread is
completely done with its thread structure, as the joining thread will
free it once unblocked.  Also, don't bother to call _sem_post() if the
thread is detached.

ok kurt@

lib/librthread/rthread.c

index 97b05fc..decb31e 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: rthread.c,v 1.36 2008/08/14 05:15:41 guenther Exp $ */
+/*     $OpenBSD: rthread.c,v 1.37 2008/08/14 05:20:44 guenther Exp $ */
 /*
  * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org>
  * All Rights Reserved.
@@ -209,14 +209,14 @@ pthread_exit(void *retval)
        LIST_REMOVE(thread, threads);
        _spinunlock(&_thread_lock);
 
-       _sem_post(&thread->donesem);
-
        stack = thread->stack;
        tid = thread->tid;
        if (thread->flags & THREAD_DETACHED)
                _rthread_free(thread);
-       else
+       else {
                _rthread_setflag(thread, THREAD_DONE);
+               _sem_post(&thread->donesem);
+       }
 
        if (tid != _initial_thread.tid)
                _rthread_add_to_reaper(tid, stack);