public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
* Implementing async canceling
@ 1999-11-18  5:05 Erik Hensema
  0 siblings, 0 replies; only message in thread
From: Erik Hensema @ 1999-11-18  5:05 UTC (permalink / raw)
  To: 'Pthreads-win32'

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1999-11-18  5:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-11-18  5:05 Implementing async canceling Erik Hensema

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).