public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
* pthread_exit() called when a cleanup handler is installed
@ 1999-07-06 10:53 Lorin Hochstein
  0 siblings, 0 replies; 2+ messages in thread
From: Lorin Hochstein @ 1999-07-06 10:53 UTC (permalink / raw)
  To: pthreads mailing list

In my code, when calling pthread_exit(), the installed cleanup functions
do NOT execute. They do execute if I call:

pthread_cancel(pthread_self());
pthread_testcancel();

I'm using the Microsoft compiler with C code, so I end up using the
WIN32 SEH version of cancel cleanup. This uses the Microsoft __try and
__finally blocks for pthread_clean_push and pthread_cleanup_pop, and
uses _endthreadex for pthread_exit.

I'm not 100% sure, but I believe that calling _endthreadex will NOT
cause the code in a "finally" statement to be executed. A fix would
require some change to the pthread.h file (perhaps doing away with WIN32
structured exception handling altogether...?)

Lorin Hochstein

^ permalink raw reply	[flat|nested] 2+ messages in thread

* RE: pthread_exit() called when a cleanup handler is installed
@ 1999-07-06 11:27 Bossom, John
  0 siblings, 0 replies; 2+ messages in thread
From: Bossom, John @ 1999-07-06 11:27 UTC (permalink / raw)
  To: 'Lorin Hochstein', pthreads mailing list

You are correct.

The proper implementation of pthread_exit() should actually perform
a
	RaiseException

as in pthread_cancel

	DWORD	exceptionInformation[ 3 ];

	exceptionInformation[0] = (DWORD) (0);
	exceptionInformation[1] = (DWORD) (0);
	exceptionInformation[2] = (DWORD) (0);

	RaiseException(
		EXCEPTION_PTHREAD_SERVICES,
		0,
		3,
		exceptionInformation );

instead of calling _endthreadex.

Performing the RaiseException will perform an SEH stack unwind all the
way back to the routine that is wrapped around your thread mainline.

To perform this properly, there needs to be some define, say
PTHREAD_EXIT_IMPLEMENTATION stuffed into exceptionInformation[ 0 ], and
the parameter from pthread_exit stuffed into exceptionInformation[ 1 ].

In the threadStart routine (the wrapper routine that actually calls your
thread routine) there needs to be some code to extract the exception
information and determine if it is really an exception or the PTHREAD_EXIT
code. 
The threadStart wrapper must be changed to perform the two calls
currently in pthread_exit (callUserDestroyRoutines and _endthreadex()
directly
(not pthread_exit)

Now, this will work fine and dandy for the C implementation of exception
handling... 
Typically, C++ users of threads have been traditionally told that to 
guarrantee that all their stack unwinding has taken place, that they should
NEVER perform a pthread_exit anywhere else except the bottom of their
thread mainline; therefore, they should return to that point in order to
exit the thread cleanly (you can use C++ exception handler to yourself
to get there quicker....)


P.S. Ross, if you need some pointers making the required code changes
     above, let me know...

John.

-----Original Message-----
From: Lorin Hochstein [ mailto:lmh@xiphos.ca ]
Sent: Tuesday, July 06, 1999 1:53 PM
To: pthreads mailing list
Subject: pthread_exit() called when a cleanup handler is installed


In my code, when calling pthread_exit(), the installed cleanup functions
do NOT execute. They do execute if I call:

pthread_cancel(pthread_self());
pthread_testcancel();

I'm using the Microsoft compiler with C code, so I end up using the
WIN32 SEH version of cancel cleanup. This uses the Microsoft __try and
__finally blocks for pthread_clean_push and pthread_cleanup_pop, and
uses _endthreadex for pthread_exit.

I'm not 100% sure, but I believe that calling _endthreadex will NOT
cause the code in a "finally" statement to be executed. A fix would
require some change to the pthread.h file (perhaps doing away with WIN32
structured exception handling altogether...?)

Lorin Hochstein

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1999-07-06 11:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-07-06 10:53 pthread_exit() called when a cleanup handler is installed Lorin Hochstein
1999-07-06 11:27 Bossom, John

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).