summaryrefslogtreecommitdiff
path: root/pthread_join.c
diff options
context:
space:
mode:
Diffstat (limited to 'pthread_join.c')
-rw-r--r--pthread_join.c21
1 files changed, 17 insertions, 4 deletions
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 <signal.h>
+
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;
}