summaryrefslogtreecommitdiff
path: root/tests/cancel5.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/cancel5.c')
-rw-r--r--tests/cancel5.c62
1 files changed, 26 insertions, 36 deletions
diff --git a/tests/cancel5.c b/tests/cancel5.c
index 808ab14..76d0a5a 100644
--- a/tests/cancel5.c
+++ b/tests/cancel5.c
@@ -72,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 */
@@ -94,33 +94,33 @@ 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;
@@ -130,37 +130,39 @@ main()
{
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.
@@ -176,34 +178,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) */