aboutsummaryrefslogtreecommitdiff
path: root/pthreads/tests/cancel2.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2013-02-13 10:41:10 +0100
committermarha <marha@users.sourceforge.net>2013-02-13 10:41:10 +0100
commitb41f74438672dd682bc01ae818cb3da654f22c1e (patch)
tree07674ef1368a5427a75080528d8cee74234f6b28 /pthreads/tests/cancel2.c
parentaaf21968deb85b635cb6aa6544df233ea5981346 (diff)
downloadvcxsrv-b41f74438672dd682bc01ae818cb3da654f22c1e.tar.gz
vcxsrv-b41f74438672dd682bc01ae818cb3da654f22c1e.tar.bz2
vcxsrv-b41f74438672dd682bc01ae818cb3da654f22c1e.zip
Updated to latest CVS version of pthreads
Diffstat (limited to 'pthreads/tests/cancel2.c')
-rw-r--r--pthreads/tests/cancel2.c59
1 files changed, 20 insertions, 39 deletions
diff --git a/pthreads/tests/cancel2.c b/pthreads/tests/cancel2.c
index 2ee596abb..941061369 100644
--- a/pthreads/tests/cancel2.c
+++ b/pthreads/tests/cancel2.c
@@ -6,10 +6,11 @@
*
* Pthreads-win32 - POSIX Threads Library for Win32
* Copyright(C) 1998 John E. Bossom
- * Copyright(C) 1999,2005 Pthreads-win32 contributors
- *
- * Contact Email: rpj@callisto.canberra.edu.au
- *
+ * Copyright(C) 1999,2012 Pthreads-win32 contributors
+ *
+ * Homepage1: http://sourceware.org/pthreads-win32/
+ * Homepage2: http://sourceforge.net/projects/pthreads4w/
+ *
* The current list of contributors is contained
* in the file CONTRIBUTORS included with the source
* code distribution. The list can also be seen at the
@@ -95,7 +96,7 @@ struct bag_t_ {
static bag_t threadbag[NUMTHREADS + 1];
-static pthread_mutex_t waitLock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_barrier_t go = NULL;
void *
mythread(void * arg)
@@ -110,18 +111,8 @@ mythread(void * arg)
/* Set to known state and type */
assert(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) == 0);
-
- switch (bag->threadnum % 2)
- {
- case 0:
- assert(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL) == 0);
- result = 0;
- break;
- case 1:
- assert(pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL) == 0);
- result = 1;
- break;
- }
+ assert(pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL) == 0);
+ result = 1;
#if !defined(__cplusplus)
__try
@@ -130,14 +121,10 @@ mythread(void * arg)
#endif
{
/* Wait for go from main */
- assert(pthread_mutex_lock(&waitLock) == 0);
- assert(pthread_mutex_unlock(&waitLock) == 0);
- sched_yield();
+ pthread_barrier_wait(&go);
+ pthread_barrier_wait(&go);
- for (;;)
- {
- pthread_testcancel();
- }
+ pthread_testcancel();
}
#if !defined(__cplusplus)
__except(EXCEPTION_EXECUTE_HANDLER)
@@ -160,7 +147,7 @@ mythread(void * arg)
*/
result += 1000;
- return (void *) (size_t)result;
+ return (void *)(size_t)result;
}
int
@@ -171,7 +158,7 @@ main()
pthread_t t[NUMTHREADS + 1];
assert((t[0] = pthread_self()).p != NULL);
- assert(pthread_mutex_lock(&waitLock) == 0);
+ assert(pthread_barrier_init(&go, NULL, NUMTHREADS + 1) == 0);
for (i = 1; i <= NUMTHREADS; i++)
{
@@ -181,23 +168,17 @@ main()
}
/*
- * Code to control or munipulate child threads should probably go here.
+ * Code to control or manipulate child threads should probably go here.
*/
- Sleep(500);
- assert(pthread_mutex_unlock(&waitLock) == 0);
-
- Sleep(500);
+ pthread_barrier_wait(&go);
for (i = 1; i <= NUMTHREADS; i++)
{
assert(pthread_cancel(t[i]) == 0);
}
- /*
- * Give threads time to run.
- */
- Sleep(NUMTHREADS * 100);
+ pthread_barrier_wait(&go);
/*
* Standard check that all threads started.
@@ -223,19 +204,19 @@ main()
void* result = (void*)0;
assert(pthread_join(t[i], &result) == 0);
- fail = ((int)(size_t)result != (int) PTHREAD_CANCELED);
+ fail = (result != PTHREAD_CANCELED);
if (fail)
{
- fprintf(stderr, "Thread %d: started %d: location %d: cancel type %s\n",
+ fprintf(stderr, "Thread %d: started %d: location %d\n",
i,
threadbag[i].started,
- (int)(size_t)result,
- (((int)(size_t)result % 2) == 0) ? "ASYNCHRONOUS" : "DEFERRED");
+ (int)(size_t)result);
}
failed |= fail;
}
assert(!failed);
+ assert(pthread_barrier_destroy(&go) == 0);
/*
* Success.