summaryrefslogtreecommitdiff
path: root/lib/librthread/rthread.c
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2006-01-05 22:17:18 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2006-01-05 22:17:18 +0000
commit475a245e08bd55854e56e3d1183e8bf3245cfc90 (patch)
treeef6a0c30575fb065e9339dfaf807b6e9ac535606 /lib/librthread/rthread.c
parentc548924531bef00e6bd5d9d6438c575ff7210c4c (diff)
In pthread_join(), check if we create a deadlock trying to join
with ourself and only free thread after a succesful join. ok marc@
Diffstat (limited to 'lib/librthread/rthread.c')
-rw-r--r--lib/librthread/rthread.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/librthread/rthread.c b/lib/librthread/rthread.c
index 992c8a830de..3de0b1d79dd 100644
--- a/lib/librthread/rthread.c
+++ b/lib/librthread/rthread.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread.c,v 1.30 2006/01/05 04:24:30 tedu Exp $ */
+/* $OpenBSD: rthread.c,v 1.31 2006/01/05 22:17:17 otto Exp $ */
/*
* Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org>
* All Rights Reserved.
@@ -204,19 +204,21 @@ pthread_join(pthread_t thread, void **retval)
{
int e;
- if (thread->flags & THREAD_DETACHED)
+ if (thread->tid == getthrid())
+ e = EDEADLK;
+ else if (thread->flags & THREAD_DETACHED)
e = EINVAL;
else {
_sem_wait(&thread->donesem, 0, 0);
if (retval)
*retval = thread->retval;
e = 0;
+ /* We should be the last having a ref to this thread, but
+ * someone stupid or evil might haved detached it;
+ * in that case the thread will cleanup itself */
+ if ((thread->flags & THREAD_DETACHED) == 0)
+ _rthread_free(thread);
}
- /* We should be the last having a ref to this thread, but
- * someone stupid or evil might haved detached it;
- * in that case the thread will cleanup itself */
- if ((thread->flags & THREAD_DETACHED) == 0)
- _rthread_free(thread);
_rthread_reaper();
return (e);