This is the mail archive of the mailing list for the pthreas-win32 project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: pthread_exit() called when a cleanup handler is installed

You are correct.

The proper implementation of pthread_exit() should actually perform

as in pthread_cancel

	DWORD	exceptionInformation[ 3 ];

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

		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
The threadStart wrapper must be changed to perform the two calls
currently in pthread_exit (callUserDestroyRoutines and _endthreadex()
(not pthread_exit)

Now, this will work fine and dandy for the C implementation of exception
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...


-----Original Message-----
From: Lorin Hochstein []
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:


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]