From b035ed05977fdef5ced4691028284b7f0ebaba19 Mon Sep 17 00:00:00 2001 From: rpj Date: Tue, 25 Jul 2000 11:27:23 +0000 Subject: 2000-07-25 Ross Johnson * dll.c (dllMain): Remove 2000-07-21 change - problem appears to be in pthread_create(). 2000-07-21 Ross Johnson * create.c (pthread_create): Set threadH to 0 (zero) everywhere. Some assignments were using NULL. Maybe it should be NULL everywhere - need to check. (I know they are nearly always the same thing - but not by definition.) * dll.c: Include resource leakage work-around. This is a partial FIXME which doesn't stop all leakage. The real problem needs to be found and fixed. - "David Baggett" * misc.c (pthread_self): Try to catch NULL thread handles at the point where they might be generated, even though they should always be valid at this point. * tsd.c (pthread_setspecific): return an error value if pthread_self() returns NULL. * sync.c (pthread_join): return an error value if pthread_self() returns NULL. * signal.c (pthread_sigmask): return an error value if pthread_self() returns NULL. --- ANNOUNCE | 8 -------- ChangeLog | 31 +++++++++++++++++++++++++++++++ create.c | 17 ++++++++++++----- dll.c | 4 +--- misc.c | 2 +- signal.c | 5 +++++ sync.c | 5 +++++ tsd.c | 15 ++++++++++----- 8 files changed, 65 insertions(+), 22 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index 3a46bab..2986e9f 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -242,14 +242,6 @@ points in applications and libraries: pthreadCancelableWait pthreadCancelableTimedWait -The library includes a non-portable function to force using the much -faster critical sections as the basis for POSIX mutexes when these are -not the default for a particular version of Windows (eg. W9x). - - pthread_mutexattr_setforcecs_np - -For example, if you don't ever use pthread_mutex_trylock() in your -application. Availability ------------ diff --git a/ChangeLog b/ChangeLog index 4c23493..e1adedd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,34 @@ +2000-07-25 Ross Johnson + + * dll.c (dllMain): Remove 2000-07-21 change - problem + appears to be in pthread_create(). + +2000-07-21 Ross Johnson + + * create.c (pthread_create): Set threadH to 0 (zero) + everywhere. Some assignments were using NULL. Maybe + it should be NULL everywhere - need to check. (I know + they are nearly always the same thing - but not by + definition.) + + * dll.c: Include resource leakage work-around. This is a + partial FIXME which doesn't stop all leakage. The real + problem needs to be found and fixed. + - "David Baggett" + + * misc.c (pthread_self): Try to catch NULL thread handles + at the point where they might be generated, even though + they should always be valid at this point. + + * tsd.c (pthread_setspecific): return an error value if + pthread_self() returns NULL. + + * sync.c (pthread_join): return an error value if + pthread_self() returns NULL. + + * signal.c (pthread_sigmask): return an error value if + pthread_self() returns NULL. + 2000-01-06 Ross Johnson * Makefile: Remove inconsistencies in 'cl' args diff --git a/create.c b/create.c index 79085bf..ac1384f 100644 --- a/create.c +++ b/create.c @@ -125,6 +125,7 @@ pthread_create (pthread_t * tid, : PThreadStateSuspended; thread->keys = NULL; + #if ! defined (__MINGW32__) || defined (__MSVCRT__) thread->threadH = (HANDLE) @@ -144,14 +145,20 @@ pthread_create (pthread_t * tid, (unsigned) stackSize, /* default stack size */ parms); - /* Make the return code to match _beginthreadex's. */ + /* + * Make the return code match _beginthreadex's. + */ if (thread->threadH == (HANDLE)-1L) - thread->threadH = NULL; + { + thread->threadH = 0; + } else if (! run) { - /* beginthread does not allow for create flags, so we do it now. - Note that beginthread itself creates the thread in SUSPENDED - mode, and then calls ResumeThread to start it. */ + /* + * beginthread does not allow for create flags, so we do it now. + * Note that beginthread itself creates the thread in SUSPENDED + * mode, and then calls ResumeThread to start it. + */ SuspendThread (thread->threadH); } diff --git a/dll.c b/dll.c index 9d59379..b0d4d2a 100644 --- a/dll.c +++ b/dll.c @@ -152,14 +152,12 @@ DllMain ( /* * Detached threads have their resources automatically - * cleaned up upon exit (others must be 'joined' + * cleaned up upon exit (others must be 'joined'). */ if (self != NULL && self->detachState == PTHREAD_CREATE_DETACHED) { - pthread_setspecific (_pthread_selfThreadKey, NULL); - _pthread_threadDestroy (self); } diff --git a/misc.c b/misc.c index 6087a6b..f2f5695 100644 --- a/misc.c +++ b/misc.c @@ -175,7 +175,7 @@ pthread_self (void) * NOTE: * GetCurrentThread only returns a pseudo-handle * which is only valid in the current thread context. - * Therefore, you should not use pass the handle to + * Therefore, you should not pass the handle to * other threads for whatever purpose. */ self->threadH = GetCurrentThread(); diff --git a/signal.c b/signal.c index db0feec..f944e0b 100644 --- a/signal.c +++ b/signal.c @@ -35,6 +35,11 @@ pthread_sigmask(int how, sigset_t const *set, sigset_t *oset) { pthread_t thread = pthread_self(); + if (thread == NULL) + { + return ENOENT; + } + /* Validate the `how' argument.*/ if (set != NULL) { diff --git a/sync.c b/sync.c index f2d1b06..b7efc29 100644 --- a/sync.c +++ b/sync.c @@ -104,6 +104,7 @@ pthread_join (pthread_t thread, void **value_ptr) * 0 'thread' has completed * EINVAL thread is not a joinable thread, * ESRCH no thread could be found with ID 'thread', + * ENOENT thread couldn't find it's own valid handle, * EDEADLK attempt to join thread with self * * ------------------------------------------------------ @@ -113,6 +114,10 @@ pthread_join (pthread_t thread, void **value_ptr) pthread_t self; self = pthread_self (); + if (self == NULL) + { + return ENOENT; + } if (pthread_equal (self, thread) != 0) { diff --git a/tsd.c b/tsd.c index f8656ce..5183cd7 100644 --- a/tsd.c +++ b/tsd.c @@ -25,11 +25,11 @@ #include "pthread.h" #include "implement.h" - -/* TLS_OUT_OF_INDEXES not defined on WinCE */ -#ifndef TLS_OUT_OF_INDEXES -#define TLS_OUT_OF_INDEXES 0xffffffff -#endif + +/* TLS_OUT_OF_INDEXES not defined on WinCE */ +#ifndef TLS_OUT_OF_INDEXES +#define TLS_OUT_OF_INDEXES 0xffffffff +#endif int pthread_key_create (pthread_key_t * key, void (*destructor) (void *)) @@ -212,6 +212,7 @@ pthread_setspecific (pthread_key_t key, const void *value) * ENOSPC a required resource has been exhausted, * ENOSYS semaphores are not supported, * EPERM the process lacks appropriate privilege + * ENOENT the thread couldn't find it's own handle * * ------------------------------------------------------ */ @@ -227,6 +228,10 @@ pthread_setspecific (pthread_key_t key, const void *value) * thread if one wasn't explicitly created */ self = pthread_self (); + if (self == NULL) + { + return ENOENT; + } } else { -- cgit v1.2.3