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_join.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'pthread_join.c') diff --git a/pthread_join.c b/pthread_join.c index 3c076e0..1c5663c 100644 --- a/pthread_join.c +++ b/pthread_join.c @@ -38,6 +38,12 @@ #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_join (pthread_t thread, void **value_ptr) @@ -74,20 +80,27 @@ pthread_join (pthread_t thread, void **value_ptr) * ------------------------------------------------------ */ { - int result = 0; + int result; pthread_t self; + /* This is the proper way to test for a valid thread ID */ + result = pthread_kill(thread, 0); + if (0 != result) + { + return result; + } + self = pthread_self (); - if (self == NULL) + if (NULL == self) { return ENOENT; } - if (pthread_equal (self, thread) != 0) + if (0 != pthread_equal (self, thread)) { result = EDEADLK; } - else if (thread->detachState == PTHREAD_CREATE_DETACHED) + else if (PTHREAD_CREATE_DETACHED == thread->detachState) { result = EINVAL; } -- cgit v1.2.3