diff options
| author | 2006-01-04 08:48:01 +0000 | |
|---|---|---|
| committer | 2006-01-04 08:48:01 +0000 | |
| commit | 62feea1b3f34966c8e147a14fdb08935d587fa90 (patch) | |
| tree | 747e2a23df139f6bd9163a4a91ac964771f33245 /lib/librthread/rthread.c | |
| parent | Remove redundant calls to bpfdetach. (diff) | |
| download | wireguard-openbsd-62feea1b3f34966c8e147a14fdb08935d587fa90.tar.xz wireguard-openbsd-62feea1b3f34966c8e147a14fdb08935d587fa90.zip | |
allow threads to be created in a detached state
do not allow a join to a detached thread
"it looks good" otto@
Diffstat (limited to 'lib/librthread/rthread.c')
| -rw-r--r-- | lib/librthread/rthread.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/librthread/rthread.c b/lib/librthread/rthread.c index b4d07b73903..eb93ec7185c 100644 --- a/lib/librthread/rthread.c +++ b/lib/librthread/rthread.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread.c,v 1.26 2006/01/01 19:32:30 marc Exp $ */ +/* $OpenBSD: rthread.c,v 1.27 2006/01/04 08:48:01 marc Exp $ */ /* * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org> * All Rights Reserved. @@ -161,12 +161,18 @@ pthread_exit(void *retval) int pthread_join(pthread_t thread, void **retval) { + int e; - _sem_wait(&thread->donesem, 0, 0); - if (retval) - *retval = thread->retval; + if (thread->flags & THREAD_DETACHED) + e = EINVAL; + else { + _sem_wait(&thread->donesem, 0, 0); + if (retval) + *retval = thread->retval; + e = 0; + } - return (0); + return (e); } int @@ -209,6 +215,8 @@ pthread_create(pthread_t *threadp, const pthread_attr_t *attr, thread->attr.guard_size = sysconf(_SC_PAGESIZE); thread->attr.stack_size -= thread->attr.guard_size; } + if (thread->attr.detach_state == PTHREAD_CREATE_DETACHED) + thread->flags |= THREAD_DETACHED; _spinlock(&_thread_lock); |
