From 8200f6ff1edca15756a22e6359f20836c4b5425b Mon Sep 17 00:00:00 2001 From: rpj Date: Wed, 27 Feb 2002 22:53:15 +0000 Subject: * exception3.c (terminateFunction): For MSVC++, call exit() rather than pthread_exit(). Add comments to explain why. * rwlock2_t.c: New test. * rwlock3_t.c: New test. * rwlock4_t.c: New test. * rwlock5_t.c: New test. * rwlock6_t.c: New test. * rwlock6_t2.c: New test. * rwlock6.c (main): Swap thread and result variables to correspond to actual thread functions. * rwlock1.c: Change test description comment to correspond to the actual test. --- tests/exception3.c | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) (limited to 'tests/exception3.c') diff --git a/tests/exception3.c b/tests/exception3.c index 5faa3e1..3d9ea86 100644 --- a/tests/exception3.c +++ b/tests/exception3.c @@ -87,16 +87,16 @@ * Create NUMTHREADS threads in addition to the Main thread. */ enum { - NUMTHREADS = 20 + NUMTHREADS = 1 }; int caught = 0; -pthread_mutex_t caughtLock = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t caughtLock; void terminateFunction () { - pthread_mutex_lock(&caughtLock); + assert(pthread_mutex_lock(&caughtLock) == 0); caught++; #if 1 { @@ -105,8 +105,34 @@ terminateFunction () fclose(fp); } #endif - pthread_mutex_unlock(&caughtLock); - pthread_exit((void *) 0); + assert(pthread_mutex_unlock(&caughtLock) == 0); + +#if defined(__MINGW32__) + /* + * Seems to work. That is, threads exit and the process + * continues. Note: need to check correct POSIX behaviour. + * My guess is: this is because of the + * eh incompatibility between g++ and MSVC++. That is, + * an exception thrown in g++ code doesn't propogate + * through or to MSVC++ code, and vice versa. + * Applications should probably not depend on this. + */ + pthread_exit((void *) 0)); +#else + /* + * Notes from the MSVC++ manual: + * 1) A term_func() should call exit(), otherwise + * abort() will be called on return to the caller. + * abort() raises SIGABRT. The default signal handler + * for all signals terminates the calling program with + * exit code 3. + * 2) A term_func() must not throw an exception. Therefore + * term_func() should not call pthread_exit() if an + * an exception-using version of pthreads-win32 library + * is being used (i.e. either pthreadVCE or pthreadVSE). + */ + exit(0); +#endif } void * @@ -115,6 +141,7 @@ exceptionedThread(void * arg) int dummy = 0x1; (void) set_terminate(&terminateFunction); + throw dummy; return (void *) 0; @@ -126,9 +153,17 @@ main() int i; pthread_t mt; pthread_t et[NUMTHREADS]; + pthread_mutexattr_t ma; assert((mt = pthread_self()) != NULL); + printf("See the notes inside of exception3.c re term_funcs.\n"); + + assert(pthread_mutexattr_init(&ma) == 0); + assert(pthread_mutexattr_settype(&ma, PTHREAD_MUTEX_ERRORCHECK) == 0); + assert(pthread_mutex_init(&caughtLock, &ma) == 0); + assert(pthread_mutexattr_destroy(&ma) == 0); + for (i = 0; i < NUMTHREADS; i++) { assert(pthread_create(&et[i], NULL, exceptionedThread, NULL) == 0); -- cgit v1.2.3