1 /* $NetBSD: cond5.c,v 1.1 2003/01/30 18:57:07 thorpej Exp $ */
9 void *threadfunc(void *arg
);
11 pthread_mutex_t mutex
= PTHREAD_MUTEX_INITIALIZER
;
12 pthread_cond_t cond
= PTHREAD_COND_INITIALIZER
;
13 int count
, total
, toggle
;
23 printf("1: condition variable test 5\n");
25 ret
= pthread_mutex_lock(&mutex
);
27 err(1, "pthread_mutex_lock(1)");
32 ret
= pthread_create(&new, NULL
, threadfunc
, &sharedval
);
34 err(1, "pthread_create");
36 printf("1: Before waiting.\n");
41 pthread_cond_broadcast(&cond
);
43 pthread_cond_wait(&cond
, &mutex
);
44 } while (toggle
!= 0);
46 printf("1: After the loop.\n");
49 pthread_mutex_unlock(&mutex
);
50 pthread_cond_signal(&cond
);
52 printf("1: After releasing the mutex.\n");
53 ret
= pthread_join(new, &joinval
);
55 err(1, "pthread_join");
57 printf("1: Thread joined. Final count = %d, total = %d\n",
60 assert(total
== COUNT
);
69 int *share
= (int *) arg
;
72 printf("2: Second thread.\n");
73 pthread_mutex_lock(&mutex
);
78 pthread_cond_signal(&cond
);
80 pthread_cond_wait(&cond
, &mutex
);
81 } while (toggle
!= 1);
83 printf("2: After the loop.\n");
84 pthread_mutex_unlock(&mutex
);