123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- #include "test.h"
- #if defined(__cplusplus)
- # if defined(__GNUC__) && __GNUC__ < 3
- # include <new.h>
- # else
- # include <new>
- using std::set_terminate;
- # endif
- enum {
- NUMTHREADS = 1
- };
- int caught = 0;
- pthread_mutex_t caughtLock;
- static void
- terminateFunction ()
- {
- assert(pthread_mutex_lock(&caughtLock) == 0);
- caught++;
- assert(pthread_mutex_unlock(&caughtLock) == 0);
- pthread_exit((void *) 0);
- }
- static void *
- exceptionedThread(void * arg)
- {
- int dummy = 0x1;
- (void) set_terminate(&terminateFunction);
- throw dummy;
- return (void *) 0;
- }
- int
- pthread_test_exception3()
- {
- int i;
- pthread_t mt;
- pthread_t et[NUMTHREADS];
- pthread_mutexattr_t ma;
- assert((mt = pthread_self()).p != NULL);
- 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);
- }
- pte_osThreadSleep(1000);
- assert(caught == NUMTHREADS);
-
- return 0;
- }
- #else
- #include <stdio.h>
- int
- pthread_test_exception3()
- {
- printf("Test N/A for this compiler environment.\n");
- return 0;
- }
- #endif
|