From 6e1c5f6a98f24308e3c9fa9f01101de6dd810153 Mon Sep 17 00:00:00 2001 From: rpj Date: Wed, 6 Apr 2005 02:16:29 +0000 Subject: fix unguarded global variable access --- tests/cleanup2.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'tests/cleanup2.c') diff --git a/tests/cleanup2.c b/tests/cleanup2.c index 50672fd..4c63918 100644 --- a/tests/cleanup2.c +++ b/tests/cleanup2.c @@ -92,14 +92,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 * @@ -134,6 +141,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++) @@ -187,7 +196,9 @@ main() assert(!failed); - assert(pop_count == NUMTHREADS); + assert(pop_count.i == NUMTHREADS); + + DeleteCriticalSection(&pop_count.cs); /* * Success. -- cgit v1.2.3