From c2f7c3e4893b6b5c4494d549b3645e06664bc1b1 Mon Sep 17 00:00:00 2001 From: julian Date: Wed, 5 Feb 1997 23:26:09 +0000 Subject: Submitted by: John Birrell uthreads update from the author. --- lib/libpthread/thread/thr_join.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'lib/libpthread/thread/thr_join.c') diff --git a/lib/libpthread/thread/thr_join.c b/lib/libpthread/thread/thr_join.c index d0093ae..161482e 100644 --- a/lib/libpthread/thread/thr_join.c +++ b/lib/libpthread/thread/thr_join.c @@ -40,14 +40,40 @@ pthread_join(pthread_t pthread, void **thread_return) { int rval = 0; int status; + pthread_t pthread1; /* Block signals: */ _thread_kern_sig_block(&status); + /* Point to the first thread in the list: */ + pthread1 = _thread_link_list; + + /* Search for the thread to join to: */ + while (pthread1 != NULL && pthread1 != pthread) { + /* Point to the next thread: */ + pthread1 = pthread1->nxt; + } + + if (pthread1 == NULL) { + /* Point to the first thread in the dead thread list: */ + pthread1 = _thread_dead; + + /* Search for the thread to join to: */ + while (pthread1 != NULL && pthread1 != pthread) { + /* Point to the next thread: */ + pthread1 = pthread1->nxt; + } + } + + if (pthread1 == NULL) { + /* Return an error: */ + errno = ESRCH; + rval = -1; + /* Check if this thread has been detached: */ - if ((pthread->attr.flags & PTHREAD_DETACHED) != 0) { + } else if ((pthread->attr.flags & PTHREAD_DETACHED) != 0) { /* Return an error: */ - _thread_seterrno(_thread_run, ESRCH); + errno = ESRCH; rval = -1; } /* Check if the thread is not dead: */ @@ -70,7 +96,7 @@ pthread_join(pthread_t pthread, void **thread_return) } } else { /* Return an error: */ - _thread_seterrno(_thread_run, ESRCH); + errno = ESRCH; rval = -1; } } else { -- cgit v1.1