summaryrefslogtreecommitdiff
path: root/tests/cleanup1.c
diff options
context:
space:
mode:
authorrpj <rpj>2005-04-06 02:16:29 +0000
committerrpj <rpj>2005-04-06 02:16:29 +0000
commit6e1c5f6a98f24308e3c9fa9f01101de6dd810153 (patch)
tree8e63d2a6f6b5de69c4b9a3a5f425f5e7db7f45d7 /tests/cleanup1.c
parentbaacf6c941b44504f703463b053de357a8adb607 (diff)
fix unguarded global variable access
Diffstat (limited to 'tests/cleanup1.c')
-rw-r--r--tests/cleanup1.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/tests/cleanup1.c b/tests/cleanup1.c
index 65645df..385aed9 100644
--- a/tests/cleanup1.c
+++ b/tests/cleanup1.c
@@ -92,7 +92,12 @@ 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
#ifdef __CLEANUP_C
@@ -100,9 +105,11 @@ __cdecl
#endif
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 *
@@ -149,6 +156,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++)
@@ -212,7 +221,9 @@ main()
assert(!failed);
- assert(pop_count == NUMTHREADS);
+ assert(pop_count.i == NUMTHREADS);
+
+ DeleteCriticalSection(&pop_count.cs);
/*
* Success.