From 2615af8ec49f7562b6f088728b6204c14e81891e Mon Sep 17 00:00:00 2001 From: guenther Date: Thu, 14 Aug 2008 05:20:44 +0000 Subject: [PATCH] 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@ --- lib/librthread/rthread.c | 8 ++++---- 1 file 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 * 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); -- 2.20.1