summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMarco S Hyman <marc@cvs.openbsd.org>2006-01-04 08:48:03 +0000
committerMarco S Hyman <marc@cvs.openbsd.org>2006-01-04 08:48:03 +0000
commitcda00a93f54161d982af94576778cce207a87d3d (patch)
treea67bee5c95f078739da433603eb514f3b43e35b7 /lib
parent8d2a2c9b339664b5ddccec9fc44cc4f9da625bc2 (diff)
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')
-rw-r--r--lib/librthread/rthread.c18
-rw-r--r--lib/librthread/rthread_attr.c13
2 files changed, 22 insertions, 9 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);
diff --git a/lib/librthread/rthread_attr.c b/lib/librthread/rthread_attr.c
index 741c4641aff..8b50aca3e7a 100644
--- a/lib/librthread/rthread_attr.c
+++ b/lib/librthread/rthread_attr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread_attr.c,v 1.5 2006/01/01 19:32:30 marc Exp $ */
+/* $OpenBSD: rthread_attr.c,v 1.6 2006/01/04 08:48:02 marc Exp $ */
/*
* Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org>
* All Rights Reserved.
@@ -59,6 +59,7 @@ pthread_attr_init(pthread_attr_t *attrp)
attr->stack_size = RTHREAD_STACK_SIZE_DEF;
attr->guard_size = sysconf(_SC_PAGESIZE);
attr->stack_size -= attr->guard_size;
+ attr->detach_state = PTHREAD_CREATE_JOINABLE;
*attrp = attr;
return (0);
@@ -104,10 +105,14 @@ pthread_attr_getdetachstate(const pthread_attr_t *attrp, int *detachstate)
int
pthread_attr_setdetachstate(pthread_attr_t *attrp, int detachstate)
{
- /* XXX detachstate should be validated here */
- (*attrp)->detach_state = detachstate;
+ int retval;
- return (0);
+ retval = (detachstate == PTHREAD_CREATE_DETACHED ||
+ detachstate == PTHREAD_CREATE_JOINABLE) ? 0 : EINVAL;
+ if (retval == 0)
+ (*attrp)->detach_state = detachstate;
+
+ return (retval);
}
int