This is the mail archive of the
pthreads-win32@sourceware.cygnus.com
mailing list for the pthreas-win32 project.
Implementing async canceling
- To: 'Pthreads-win32' <pthreads-win32 at sourceware dot cygnus dot com>
- Subject: Implementing async canceling
- From: Erik Hensema <erik dot hensema at group2000 dot nl>
- Date: Thu, 18 Nov 1999 14:03:54 +0100
Hi,
I'm trying to design a way to make async canceling work using Jason Nye's
method.
The way I'm reading Posix, an async cancel should immediately cancel the
target thread if canceling is enabled, and otherwise defere the cancel until
the target thread enables canceling with pthread_setcancelstate().
Canceling should allways call the thread's cleanup handlers.
So, how could this be implemented?
I think that pthread_cancel() should do something like this:
if ( thread->cancelType == PTHREAD_CANCEL_ASYNCRONOUS
&& thread->cancelState == PTHREAD_CANCEL_ENABLE )
{
CancelThread(thread->threadH); /* Jason's implementation */
}
else
{ /* deferred cancelation or async cancelation with cancel disabled */
SetEvent(thread->cancelEvent);
}
This immediately cancels the thread if async and canceling are enabled.
Otherwise, it sets the cancelEvent for a deferred cancel.
Now, pthread_setcancelstate() should check if there are pending async cancel
requests:
.
. code for setting the new cancel state is placed here
.
if (self->cancelState == PTHREAD_CANCEL_ENABLE
&& self->cancelType == PTHREAD_CANCEL_ASYNCHRONOUS
&& ( WaitForSingleObject(self->cancelEvent, 0) == WAIT_OBJECT_0 ))
{
/* the thread has a cancel request pending, perform the
cancel */
CancelMe()
}
Note that you should consider all of this as pseudocode; it's just a simple
design and has no error checking nor has it ever seen a compiler.
CancelMe() should be a function that calls the thread's cleanup handlers
etc. Is there yet such a function available? CancelMe() is also the function
that CancelThread() sets the target threads eip to.
My questions are:
a) any comments on this design?
b) what should CancelMe() do?
c) is this implementation Posix complient?
--
Erik Hensema
Work: erik.hensema@group2000.nl
Home: erik@hensema.xs4all.nl