diff options
author | Philip Guenthe <guenther@cvs.openbsd.org> | 2008-08-14 05:20:45 +0000 |
---|---|---|
committer | Philip Guenthe <guenther@cvs.openbsd.org> | 2008-08-14 05:20:45 +0000 |
commit | ee44450406aeeb5199575aa1bdaf88c249a2e52b (patch) | |
tree | c9c37a5b59907e385fe3129986ae9cb3301d6dd1 | |
parent | 5decd3a7dcf38a38c8b61222d7120e690ba4105c (diff) |
Fix 5771/library: in pthread_exit(), delay the call to _sem_post() that
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@
-rw-r--r-- | lib/librthread/rthread.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/librthread/rthread.c b/lib/librthread/rthread.c index 97b05fc847a..decb31e1c5b 100644 --- a/lib/librthread/rthread.c +++ b/lib/librthread/rthread.c @@ -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); |