change 5M to 50000; add more printfs.
This commit is contained in:
parent
42d6b7198b
commit
9dffc0237c
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: cond4.c,v 1.1 2003/01/30 18:53:48 thorpej Exp $ */
|
/* $NetBSD: cond4.c,v 1.2 2007/01/20 19:21:18 christos Exp $ */
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
|
@ -11,6 +11,7 @@ void *threadfunc(void *arg);
|
||||||
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
|
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
|
||||||
int count, total, toggle;
|
int count, total, toggle;
|
||||||
|
#define COUNT 50000
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -25,7 +26,7 @@ int main(int argc, char *argv[])
|
||||||
if (ret)
|
if (ret)
|
||||||
err(1, "pthread_mutex_lock(1)");
|
err(1, "pthread_mutex_lock(1)");
|
||||||
|
|
||||||
count = 5000000;
|
count = COUNT;
|
||||||
toggle = 0;
|
toggle = 0;
|
||||||
|
|
||||||
ret = pthread_create(&new, NULL, threadfunc, &sharedval);
|
ret = pthread_create(&new, NULL, threadfunc, &sharedval);
|
||||||
|
@ -37,6 +38,9 @@ int main(int argc, char *argv[])
|
||||||
count--;
|
count--;
|
||||||
total++;
|
total++;
|
||||||
toggle = 1;
|
toggle = 1;
|
||||||
|
#if 0
|
||||||
|
printf("1: Before signal %d.\n", count);
|
||||||
|
#endif
|
||||||
pthread_cond_signal(&cond);
|
pthread_cond_signal(&cond);
|
||||||
do {
|
do {
|
||||||
pthread_cond_wait(&cond, &mutex);
|
pthread_cond_wait(&cond, &mutex);
|
||||||
|
@ -56,7 +60,7 @@ int main(int argc, char *argv[])
|
||||||
printf("1: Thread joined. Final count = %d, total = %d\n",
|
printf("1: Thread joined. Final count = %d, total = %d\n",
|
||||||
count, total);
|
count, total);
|
||||||
assert(count == 0);
|
assert(count == 0);
|
||||||
assert(total == 5000000);
|
assert(total == COUNT);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -69,10 +73,14 @@ void *threadfunc(void *arg)
|
||||||
|
|
||||||
printf("2: Second thread.\n");
|
printf("2: Second thread.\n");
|
||||||
pthread_mutex_lock(&mutex);
|
pthread_mutex_lock(&mutex);
|
||||||
|
printf("2: Before the loop.\n");
|
||||||
while (count>0) {
|
while (count>0) {
|
||||||
count--;
|
count--;
|
||||||
total++;
|
total++;
|
||||||
toggle = 0;
|
toggle = 0;
|
||||||
|
#if 0
|
||||||
|
printf("2: Before signal %d.\n", count);
|
||||||
|
#endif
|
||||||
pthread_cond_signal(&cond);
|
pthread_cond_signal(&cond);
|
||||||
do {
|
do {
|
||||||
pthread_cond_wait(&cond, &mutex);
|
pthread_cond_wait(&cond, &mutex);
|
||||||
|
|
Loading…
Reference in New Issue