From a50745ec922a917513029f3f87bf820827b43f29 Mon Sep 17 00:00:00 2001 From: rpj Date: Thu, 14 Aug 2003 08:53:17 +0000 Subject: Reuse of thread IDs, improved thread ID validation, new tests, bug fixes. --- pthread_detach.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'pthread_detach.c') diff --git a/pthread_detach.c b/pthread_detach.c index 423997d..a54a7e8 100644 --- a/pthread_detach.c +++ b/pthread_detach.c @@ -38,9 +38,15 @@ #include "pthread.h" #include "implement.h" +/* + * Not needed yet, but defining it should indicate clashes with build target + * environment that should be fixed. + */ +#include + int -pthread_detach (pthread_t tid) +pthread_detach (pthread_t thread) /* * ------------------------------------------------------ * DOCPUBLIC @@ -70,17 +76,21 @@ pthread_detach (pthread_t tid) { int result; - if (tid == NULL || - tid->detachState == PTHREAD_CREATE_DETACHED) + /* This is the proper way to test for a valid thread. */ + result = pthread_kill(thread, 0); + if (0 != result) { + return result; + } + if (thread->detachState == PTHREAD_CREATE_DETACHED) + { result = EINVAL; - } else { result = 0; - tid->detachState = PTHREAD_CREATE_DETACHED; + thread->detachState = PTHREAD_CREATE_DETACHED; } return (result); -- cgit v1.2.3