From 96600f6d50eeeef1f660352b8455d4df1aed69ff Mon Sep 17 00:00:00 2001 From: rpj Date: Wed, 29 Jul 1998 01:57:32 +0000 Subject: Wed Jul 29 11:39:03 1998 Ross Johnson * private.c: Corrections in comments. (_pthread_new_thread): Alter "if" flow to be more natural. --- ChangeLog | 3 +++ private.c | 47 ++++++++++++++++++++++++----------------------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4836d5f..f3fddb7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ Wed Jul 29 11:39:03 1998 Ross Johnson + * private.c: Corrections in comments. + (_pthread_new_thread): Alter "if" flow to be more natural. + * cleanup.c (_pthread_handler_push): Same as below. * create.c (pthread_create): Same as below. diff --git a/private.c b/private.c index f6acf70..2ac2e31 100644 --- a/private.c +++ b/private.c @@ -12,10 +12,11 @@ /* Thread ID management. --------------------- - We started by simply mapping the Win32 thread handle to directly to - pthread_t. Then, is order to process pthread_join()'s, needed to be - able to keep our POSIX thread ID (pthread_t) around after the Win32 - thread has terminated and possibly reused the Win32 handle. + We started by simply mapping the Win32 thread handle directly to + pthread_t. However, in order to process pthread_join()'s, we need + to be able to keep our POSIX thread ID (pthread_t) around after the + Win32 thread has terminated. Win32 may reuse the Win32 handle during that + time, which will conflict. The pthread_t value is now actually the pointer to a thread struct: @@ -47,7 +48,7 @@ Having the thread ID as a pointer to the thread struct itself avoids the need to search the threads table in all but the initial - occation where we create the thread. + occasion where we create the thread. Initially we used a hash function to select a free thread struct from the table, possibly needing a walk through the table if the @@ -73,20 +74,20 @@ The code for choosing a new (pthread_t) thread from the pool of free thread structs looks like: - if (_pthread_reuse_top == -1) + if (_pthread_reuse_top >= 0) { - if (_pthread_virgin_next >= PTHREAD_THREADS_MAX) - { - return EAGAIN; - } - else - { - thread = _pthread_virgin[_pthread_virgin_next++]; - } + new_thread = _pthread_reuse[_pthread_reuse_top--]; } else { - thread = _pthread_reuse[_pthread_reuse_top--]; + if (_pthread_virgin_next < PTHREAD_THREADS_MAX) + { + new_thread = _pthread_virgin[_pthread_virgin_next++]; + } + else + { + return EAGAIN; + } } @@ -101,21 +102,21 @@ _pthread_new_thread(pthread_t * thread) { pthread_t new_thread; - if (_pthread_reuse_top == -1) + if (_pthread_reuse_top >= 0) + { + new_thread = _pthread_reuse[_pthread_reuse_top--]; + } + else { - if (_pthread_virgin_next >= PTHREAD_THREADS_MAX) + if (_pthread_virgin_next < PTHREAD_THREADS_MAX) { - return EAGAIN; + new_thread = _pthread_virgin[_pthread_virgin_next++]; } else { - new_thread = _pthread_virgin[_pthread_virgin_next++]; + return EAGAIN; } } - else - { - new_thread = _pthread_reuse[_pthread_reuse_top--]; - } new_thread->win32handle = NULL; new_thread->ptstatus = _PTHREAD_NEW; -- cgit v1.2.3