9 void *threadfunc(void *arg
);
11 pthread_mutex_t mutex
= PTHREAD_MUTEX_INITIALIZER
;
12 pthread_cond_t cond
= PTHREAD_COND_INITIALIZER
;
15 main(int argc
, char *argv
[])
22 printf("1: condition variable test 3\n");
25 pthread_mutex_lock(&mutex
);
29 ret
= pthread_create(&new, NULL
, threadfunc
, &sharedval
);
31 err(1, "pthread_create");
33 printf("1: Before waiting.\n");
36 pthread_cond_wait(&cond
, &mutex
);
37 printf("1: After waiting, in loop.\n");
38 } while (sharedval
!= 0);
40 printf("1: After the loop.\n");
42 pthread_mutex_unlock(&mutex
);
44 printf("1: After releasing the mutex.\n");
45 ret
= pthread_join(new, &joinval
);
47 err(1, "pthread_join");
49 printf("1: Thread joined.\n");
57 int *share
= (int *) arg
;
59 printf("2: Second thread.\n");
61 printf("2: Locking mutex\n");
62 pthread_mutex_lock(&mutex
);
63 printf("2: Got mutex.\n");
64 printf("Shared value: %d. Changing to 0.\n", *share
);
67 /* Signal first, then unlock, for a different test than #1. */
68 pthread_cond_signal(&cond
);
69 pthread_mutex_unlock(&mutex
);