public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
From: Ross Johnson <rpj@ise.canberra.edu.au>
To: "'Pthreads-win32'" <pthreads-win32@sourceware.cygnus.com>
Subject: Re: asynchronous cancellation
Date: Tue, 16 Nov 1999 19:17:00 -0000	[thread overview]
Message-ID: <Pine.LNX.4.05.9911171352420.256-100000@swan.canberra.edu.au> (raw)
In-Reply-To: <382CCAEB.ABCCED24@nbnet.nb.ca>

John, Jason, all,

The following applies to the C++ version of things, but SEH versions
should hopefully be similar.

Following on from John's explanation of C++ stack unwinding etc, and
the fact that pthreads-win32 implements cancelation by throwing an
exception, and the fact that the C++ version of pthread_cleanup_pop
is implemented as a destructor (after John's original
implementation):

For deferred cancelation:
1) stack unwinding should occur properly IMO

2) cleanup handlers should be called.

For async cancelation:
1) Jason's method could be used with the following simple change to
   AsyncCancelPoint to work with the current pthreads-win32
   mechanism:

void cancelThread(HANDLE hThread)
{
    ::SuspendThread(hThread);
    if (::WaitForSingleObject(hThread, 0) != WAIT_TIMEDOUT) {
            // Ok, thread did not exit before we got to it.
           CONTEXT context;
           context.ContextFlags = CONTEXT_CONTROL;
           ::GetThreadContext(hThread, &context);
           // _x86 only!!!
           context.Eip = (DWORD)AsyncCancelPoint;
           ::SetThreadContext(hThread, &context);
           ::ResumeThread(hThread);
    }
}

// declare AsyncCancelPoint:
void AsyncCancelPoint()
{
    // This is all it needs to do to call cleanup handlers,
    // call object destructors, and exit the thread.
    throw Pthread_exception_cancel();
}

For cancelation in general:
1) the following macro should be included in pthread.h:

#define catch(E) \
	catch(Pthread_exception_cancel) { \
		throw(); \
	} \
	catch(E)


Is this getting closer to the ideal, or am I way off the track?

Ross

+----------------------+---+
| Ross Johnson         |   | E-Mail: rpj@ise.canberra.edu.au
| Info Sciences and Eng|___|
| University of Canberra   | FAX:    +61 6 2015227
| PO Box 1                 |
| Belconnen  ACT    2616   | WWW:    http://willow.canberra.edu.au/~rpj/
| AUSTRALIA                |
+--------------------------+


  reply	other threads:[~1999-11-16 19:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-11-12 18:08 Jason Nye
1999-11-16 19:17 ` Ross Johnson [this message]
1999-11-17  4:46   ` Jason Nye
1999-11-15  7:45 Bossom, John
1999-11-16  1:30 ` Ross Johnson
1999-11-16 13:11   ` Jason Nye
1999-11-16 14:40 Bossom, John

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.05.9911171352420.256-100000@swan.canberra.edu.au \
    --to=rpj@ise.canberra.edu.au \
    --cc=pthreads-win32@sourceware.cygnus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).