diff options
author | rpj <rpj> | 2004-05-17 01:38:02 +0000 |
---|---|---|
committer | rpj <rpj> | 2004-05-17 01:38:02 +0000 |
commit | 771465fed0cf50ee2dd790723245fc091699c324 (patch) | |
tree | d8c18d095a33fe7c4564bd90c5f313bb9e4057dd /tests/cancel3.c | |
parent | 8b14911744f58cbe3730703f3fcc41cd969fd0f3 (diff) |
re-indentation, bug fixes, hooks for pre-emptive async cancelation
Diffstat (limited to 'tests/cancel3.c')
-rw-r--r-- | tests/cancel3.c | 71 |
1 files changed, 31 insertions, 40 deletions
diff --git a/tests/cancel3.c b/tests/cancel3.c index ed1df0f..c3657d6 100644 --- a/tests/cancel3.c +++ b/tests/cancel3.c @@ -33,13 +33,13 @@ * * -------------------------------------------------------------------------- * - * Test Synopsis: Test asynchronous cancelation. + * Test Synopsis: Test asynchronous cancelation (alertable or non-alertable). * * Test Method (Validation or Falsification): * - * * Requirements Tested: - * - + * - Async cancel if thread is not blocked (i.e. voluntarily resumes if blocked). * * Features Tested: * - @@ -62,7 +62,8 @@ * * Assumptions: * - have working pthread_create, pthread_self, pthread_mutex_lock/unlock - * pthread_testcancel, pthread_cancel, pthread_join + * pthread_testcancel, pthread_cancel, pthread_join. + * - quserex.dll and alertdrv.sys are not available. * * Pass Criteria: * - Process returns zero exit status. @@ -71,19 +72,19 @@ * - Process returns non-zero exit status. */ -#if defined(_MSC_VER) || defined(__cplusplus) - #include "test.h" /* * Create NUMTHREADS threads in addition to the Main thread. */ -enum { +enum +{ NUMTHREADS = 4 }; typedef struct bag_t_ bag_t; -struct bag_t_ { +struct bag_t_ +{ int threadnum; int started; /* Add more per-thread state variables here */ @@ -93,75 +94,77 @@ struct bag_t_ { static bag_t threadbag[NUMTHREADS + 1]; void * -mythread(void * arg) +mythread (void *arg) { - int result = ((int)PTHREAD_CANCELED + 1); - bag_t * bag = (bag_t *) arg; + int result = ((int) PTHREAD_CANCELED + 1); + bag_t *bag = (bag_t *) arg; - assert(bag == &threadbag[bag->threadnum]); - assert(bag->started == 0); + assert (bag == &threadbag[bag->threadnum]); + assert (bag->started == 0); bag->started = 1; /* Set to known state and type */ - assert(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) == 0); + assert (pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL) == 0); - assert(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL) == 0); + assert (pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL) == 0); /* * We wait up to 10 seconds, waking every 0.1 seconds, * for a cancelation to be applied to us. */ for (bag->count = 0; bag->count < 100; bag->count++) - Sleep(100); + Sleep (100); return (void *) result; } int -main() +main () { int failed = 0; int i; pthread_t t[NUMTHREADS + 1]; - assert((t[0] = pthread_self()) != NULL); + assert ((t[0] = pthread_self ()) != NULL); for (i = 1; i <= NUMTHREADS; i++) { threadbag[i].started = 0; threadbag[i].threadnum = i; - assert(pthread_create(&t[i], NULL, mythread, (void *) &threadbag[i]) == 0); + assert (pthread_create (&t[i], NULL, mythread, (void *) &threadbag[i]) + == 0); } /* * Code to control or munipulate child threads should probably go here. */ - Sleep(500); + Sleep (500); for (i = 1; i <= NUMTHREADS; i++) { - assert(pthread_cancel(t[i]) == 0); + assert (pthread_cancel (t[i]) == 0); } /* * Give threads time to run. */ - Sleep(NUMTHREADS * 100); + Sleep (NUMTHREADS * 100); /* * Standard check that all threads started. */ for (i = 1; i <= NUMTHREADS; i++) - { + { if (!threadbag[i].started) { failed |= !threadbag[i].started; - fprintf(stderr, "Thread %d: started %d\n", i, threadbag[i].started); + fprintf (stderr, "Thread %d: started %d\n", i, + threadbag[i].started); } } - assert(!failed); + assert (!failed); /* * Check any results here. Set "failed" and only print output on failure. @@ -177,34 +180,22 @@ main() * a return value of PTHREAD_CANCELED confirms that async * cancelation succeeded. */ - assert(pthread_join(t[i], (void **) &result) == 0); + assert (pthread_join (t[i], (void **) &result) == 0); fail = (result != (int) PTHREAD_CANCELED); if (fail) { - fprintf(stderr, "Thread %d: started %d: count %d\n", - i, - threadbag[i].started, - threadbag[i].count); + fprintf (stderr, "Thread %d: started %d: count %d\n", + i, threadbag[i].started, threadbag[i].count); } failed = (failed || fail); } - assert(!failed); + assert (!failed); /* * Success. */ return 0; } - -#else /* defined(_MSC_VER) || defined(__cplusplus) */ - -int -main() -{ - return 0; -} - -#endif /* defined(_MSC_VER) || defined(__cplusplus) */ |