This is the mail archive of the
pthreads-win32@sources.redhat.com
mailing list for the pthreas-win32 project.
Reuse of Thread IDs
- From: Ross Johnson <rpj at callisto dot canberra dot edu dot au>
- To: pthreads-win32 at sources dot redhat dot com
- Date: Thu, 14 Aug 2003 20:37:44 +1000
- Subject: Reuse of Thread IDs
- Reply-to: rpj at callisto dot canberra dot edu dot au
Hi all,
Nicolas Barry has discovered that a couple of routines
(pthread_getschedparam etc) had rather iffy thread validation checks
that could ultimately segfault due to pthread_t being a simple pointer
to alloced memory that was being freed on thread exit. This weakness in
the library hasn't been entirely unanticipated though, but it's time has
arrived.
These routines also returned an incorrect error value (EINVAL instead or
ESRCH).
As a result, I've changed the way that threads are managed slightly.
The validation check is now stronger and goes as far as checking the
validity of the underlying Win32 thread HANDLE stored in the POSIX
thread handle. To make work, the library (as of the current CVS version)
now no longer frees pthread structs when a thread exits. Instead it
pushes disused structs onto a LIFO stack (implemented as a simple
guarded linked list). Thread handles are still calloced if no disused
handles are available.
There is now also an exported pthread_kill() routine, but it only
accepts a zero value for the signal arg. Any other value will return
EINVAL. It's intended to be used by applications that want to test the
validity of a POSIX thread handle (as intended by the standard).
I've added a few more tests to the test suite, and the library passes
all of the tests so hopefully these changes will be pretty transparent
to your applications. I hope to get a new snapshot out soon, with
pre-built DLLs and libs as usual.
I've also made changes that fix a number of problems that came up when I
changed to using the current MinGW + MsysDTK environment.
Regards.
Ross