summaryrefslogtreecommitdiff
path: root/tests/cleanup3.c
diff options
context:
space:
mode:
authorrpj <rpj>2005-04-06 02:29:15 +0000
committerrpj <rpj>2005-04-06 02:29:15 +0000
commit13bd1e4d017a1c306e465219df9e245a4201726e (patch)
treed6d788a55449bd7ea1c5ea05f5af9bc0bbf9b2c7 /tests/cleanup3.c
parentf19dd198df0106b07245d80d150a3d569b6cdf4d (diff)
''
Diffstat (limited to 'tests/cleanup3.c')
-rw-r--r--tests/cleanup3.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/tests/cleanup3.c b/tests/cleanup3.c
index a12337d..b595ab4 100644
--- a/tests/cleanup3.c
+++ b/tests/cleanup3.c
@@ -93,14 +93,21 @@ struct bag_t_ {
static bag_t threadbag[NUMTHREADS + 1];
-static int pop_count = 0;
+typedef struct {
+ int i;
+ CRITICAL_SECTION cs;
+} sharedInt_t;
+
+static sharedInt_t pop_count = {0, {0}};
static void
increment_pop_count(void * arg)
{
- int * c = (int *) arg;
+ sharedInt_t * sI = (sharedInt_t *) arg;
- (*c)++;
+ EnterCriticalSection(&sI->cs);
+ sI->i++;
+ LeaveCriticalSection(&sI->cs);
}
void *
@@ -120,7 +127,9 @@ mythread(void * arg)
sched_yield();
- pop_count--;
+ EnterCriticalSection(&pop_count.cs);
+ pop_count.i--;
+ LeaveCriticalSection(&pop_count.cs);
pthread_cleanup_pop(0);
#ifdef _MSC_VER
@@ -137,6 +146,8 @@ main()
int i;
pthread_t t[NUMTHREADS + 1];
+ InitializeCriticalSection(&pop_count.cs);
+
assert((t[0] = pthread_self()).p != NULL);
for (i = 1; i <= NUMTHREADS; i++)
@@ -190,7 +201,9 @@ main()
assert(!failed);
- assert(pop_count == -(NUMTHREADS));
+ assert(pop_count.i == -(NUMTHREADS));
+
+ DeleteCriticalSection(&pop_count.cs);
/*
* Success.