summaryrefslogtreecommitdiff
path: root/tests/exception3.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/exception3.c')
-rw-r--r--tests/exception3.c72
1 files changed, 15 insertions, 57 deletions
diff --git a/tests/exception3.c b/tests/exception3.c
index b820b4b..66f4173 100644
--- a/tests/exception3.c
+++ b/tests/exception3.c
@@ -39,17 +39,16 @@
* - Process returns non-zero exit status.
*/
+#include "test.h"
+
+#if defined(__cplusplus)
-#if defined(_MSC_VER) && defined(__cplusplus)
+#if defined(_MSC_VER)
#include <eh.h>
#else
#include <new.h>
#endif
-#if defined(_MSC_VER) || defined(__cplusplus)
-
-#include "test.h"
-
/*
* Create NUMTHREADS threads in addition to the Main thread.
*/
@@ -60,28 +59,12 @@ enum {
int caught = 0;
pthread_mutex_t caughtLock = PTHREAD_MUTEX_INITIALIZER;
-#if defined(_MSC_VER) && !defined(__cplusplus)
-
-LONG unhandledExceptionFilter (EXCEPTION_POINTERS *ep)
-{
- if (ep->ExceptionRecord->ExceptionCode == 0x1)
- {
- pthread_mutex_lock(&caughtLock);
- caught++;
- pthread_mutex_unlock(&caughtLock);
- }
-
- return EXCEPTION_CONTINUE_EXECUTION;
-}
-
-#elif defined(__cplusplus)
-
void
terminateFunction ()
{
pthread_mutex_lock(&caughtLock);
caught++;
-#if 1
+#if 0
{
FILE * fp = fopen("pthread.log", "a");
fprintf(fp, "Caught = %d\n", caught);
@@ -92,28 +75,15 @@ terminateFunction ()
pthread_exit((void *) 0);
}
-#endif
-
void *
exceptionedThread(void * arg)
{
int dummy = 0x1;
- {
-#if defined(_MSC_VER) && !defined(__cplusplus)
+ (void) set_terminate(&terminateFunction);
+ throw dummy;
- RaiseException(dummy, 0, 0, NULL);
-
-#elif defined(__cplusplus)
-
- (void) set_terminate(&terminateFunction);
-
- throw dummy;
-
-#endif
- }
-
- return (void *) 100;
+ return (void *) 0;
}
int
@@ -125,25 +95,13 @@ main()
assert((mt = pthread_self()) != NULL);
- {
-#if defined(_MSC_VER) && !defined(__cplusplus)
- LPTOP_LEVEL_EXCEPTION_FILTER oldHandler;
- oldHandler = SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER) unhandledExceptionFilter);
-#endif
-
- for (i = 0; i < NUMTHREADS; i++)
- {
- assert(pthread_create(&et[i], NULL, exceptionedThread, NULL) == 0);
- }
-
-#if defined(_MSC_VER) && !defined(__cplusplus)
- (void) SetUnhandledExceptionFilter(oldHandler);
-#endif
+ for (i = 0; i < NUMTHREADS; i++)
+ {
+ assert(pthread_create(&et[i], NULL, exceptionedThread, NULL) == 0);
+ }
- Sleep(30000);
- }
+ Sleep(10000);
- printf("Caught = %d\n", caught);
assert(caught == NUMTHREADS);
/*
@@ -152,7 +110,7 @@ main()
return 0;
}
-#else /* defined(_MSC_VER) || defined(__cplusplus) */
+#else /* defined(__cplusplus) */
int
main()
@@ -161,4 +119,4 @@ main()
return 0;
}
-#endif /* defined(_MSC_VER) || defined(__cplusplus) */
+#endif /* defined(__cplusplus) */