From 6a1d5a165901cbf6b76376a6c35d2306b55a2f72 Mon Sep 17 00:00:00 2001 From: jb Date: Fri, 3 Apr 1998 09:31:15 +0000 Subject: Add a magic field to the pthread structure to help recognize valid threads from invalid ones. The pthread structure is opaque to the user so this change does not cause any incompatibilities. Hopefully this change will help code that was written for draft 4 fail gracefully if the programmer ignores the compiler warning about the change in the level of indirection for the argument passed to pthread_detach(). I got burnt, so I fixed then (expletive deleted) thing. These functions comply with the revised standard. That should shut Terry up! --- lib/libpthread/thread/thr_join.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (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 63d0d58..9e86a01 100644 --- a/lib/libpthread/thread/thr_join.c +++ b/lib/libpthread/thread/thr_join.c @@ -42,6 +42,16 @@ pthread_join(pthread_t pthread, void **thread_return) int status; pthread_t pthread1; + /* Check if the caller has specified an invalid thread: */ + if (pthread == NULL || pthread->magic != PTHREAD_MAGIC) + /* Invalid thread: */ + return(EINVAL); + + /* Check if the caller has specified itself: */ + if (pthread == _thread_run) + /* Avoid a deadlock condition: */ + return(EDEADLK); + /* Block signals: */ _thread_kern_sig_block(&status); -- cgit v1.1