4 * Test Synopsis: Test setting cancel state and cancel type.
7 * Test Method (Validation or Falsification):
10 * Requirements Tested:
11 * - pthread_setcancelstate function
12 * - pthread_setcanceltype function
30 * - File name, Line number, and failed expression on failure.
31 * - No output on success.
34 * - pthread_create, pthread_self work.
37 * - Process returns zero exit status.
40 * - Process returns non-zero exit status.
46 * Create NUMTHREADS threads in addition to the Main thread.
52 typedef struct bag_t_ bag_t;
56 /* Add more per-thread state variables here */
59 static bag_t threadbag[NUMTHREADS + 1];
64 bag_t * bag = (bag_t *) arg;
66 assert(bag == &threadbag[bag->threadnum]);
67 assert(bag->started == 0);
75 assert(pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate) == 0);
76 assert(oldstate == PTHREAD_CANCEL_ENABLE); /* Check default */
77 assert(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) == 0);
78 assert(pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL) == 0);
79 assert(pthread_setcancelstate(oldstate, &oldstate) == 0);
80 assert(oldstate == PTHREAD_CANCEL_DISABLE); /* Check setting */
82 assert(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype) == 0);
83 assert(oldtype == PTHREAD_CANCEL_DEFERRED); /* Check default */
84 assert(pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL) == 0);
85 assert(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL) == 0);
86 assert(pthread_setcanceltype(oldtype, &oldtype) == 0);
87 assert(oldtype == PTHREAD_CANCEL_ASYNCHRONOUS); /* Check setting */
98 pthread_t t[NUMTHREADS + 1];
100 assert((t[0] = pthread_self()) != NULL);
102 for (i = 1; i <= NUMTHREADS; i++)
104 threadbag[i].started = 0;
105 threadbag[i].threadnum = i;
106 assert(pthread_create(&t[i], NULL, mythread, (void *) &threadbag[i]) == 0);
110 * Code to control or munipulate child threads should probably go here.
114 * Give threads time to run.
116 Sleep(NUMTHREADS * 1000);
119 * Standard check that all threads started.
121 for (i = 1; i <= NUMTHREADS; i++)
123 failed = !threadbag[i].started;
127 fprintf(stderr, "Thread %d: started %d\n", i, threadbag[i].started);
134 * Check any results here. Set "failed" and only print ouput on failure.
136 for (i = 1; i <= NUMTHREADS; i++)