123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- #include "test.h"
- #if defined(__cplusplus) && defined(PTE_SUPPORT_ASYNC_CANCEL)
- enum {
- NUMTHREADS = 4
- };
- static void *
- exceptionedThread(void * arg)
- {
- int dummy = 0;
- int result = ((int)PTHREAD_CANCELED + 1);
-
- assert(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) == 0);
- assert(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL) == 0);
- pte_osThreadSleep(100);
- try
- {
-
- throw dummy;
- }
- catch (...)
- {
-
- result = ((int)PTHREAD_CANCELED + 2);
- }
- return (void *) result;
- }
- static void *
- canceledThread(void * arg)
- {
- int result = ((int)PTHREAD_CANCELED + 1);
- int count;
-
- assert(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) == 0);
- assert(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL) == 0);
- try
- {
-
- for (count = 0; count < 100; count++)
- pte_osThreadSleep(100);
- }
- catch (...)
- {
-
- result = ((int)PTHREAD_CANCELED + 2);
- }
- return (void *) result;
- }
- int
- pthread_test_exception1()
- {
- int failed = 0;
- int i;
- pthread_t mt;
- pthread_t et[NUMTHREADS];
- pthread_t ct[NUMTHREADS];
- assert((mt = pthread_self()).p != NULL);
- for (i = 0; i < NUMTHREADS; i++)
- {
- assert(pthread_create(&et[i], NULL, exceptionedThread, (void *) 0) == 0);
- assert(pthread_create(&ct[i], NULL, canceledThread, NULL) == 0);
- }
-
- pte_osThreadSleep(1000);
- for (i = 0; i < NUMTHREADS; i++)
- {
- assert(pthread_cancel(ct[i]) == 0);
- }
-
- pte_osThreadSleep(NUMTHREADS * 1000);
-
- failed = 0;
- for (i = 0; i < NUMTHREADS; i++)
- {
- int fail = 0;
- int result = 0;
-
- assert(pthread_join(ct[i], (void **) &result) == 0);
- assert(!(fail = (result != (int) PTHREAD_CANCELED)));
- failed = (failed || fail);
-
- assert(pthread_join(et[i], (void **) &result) == 0);
- assert(!(fail = (result != ((int) PTHREAD_CANCELED + 2))));
- failed = (failed || fail);
- }
- assert(!failed);
-
- return 0;
- }
- #else
- int
- pthread_test_exception1()
- {
- printf("Test N/A for this compiler environment.\n");
- return 0;
- }
- #endif
|