This is the mail archive of the
pthreads-win32@sources.redhat.com
mailing list for the pthreas-win32 project.
Problem in pthread_cancel() ?
- To: <pthreads-win32 at sources dot redhat dot com>
- Subject: Problem in pthread_cancel() ?
- From: "Ollie Leahy" <ollie at mpt dot ie>
- Date: Wed, 6 Sep 2000 09:33:03 +0100
I don't know whether I am mis-using pthreads or if
there is a problem in the pthreads-win32 implementation.
When my process is closing down I want all pthreads
to complete before I finally return from the process.
To do this I send a pthread_cancel() to those threads
that are blocking (on an accept() or a recv() call)
on Linux this works but with pthread-win32 if I call
pthread_cancel() from the main process the process
core dumps. If I create a thread and call cancel()
from the thread then everything works fine.
I had a quick look at the code for pthread_cancel() and
the problem seems to be that pthread_cancel() tests
whether it is being called to cancel the calling thread
and references the variable 'self'. But since I call the
function from the process and not from a thread self
is NULL, so as soon as self is dereferenced the process
crashes.
I have fixed my problem by creating a thread to call
cancel, and I've also hacked the pthread-win32 code
so that if self is NULL pthread_cancel() does not
try to defreference it. I would like to know whether
I'm trying to do something illegal as far as pthreads
are concerned or whether there is a bug in the win32
implementation.
Regards,
Ollie