2 * pthread_cond_wait() test program.
3 * See also https://bugs.kde.org/show_bug.cgi?id=235681.
13 pthread_mutex_t mutex
;
14 pthread_cond_t cond_var
;
18 static void *run_fn(void *v
)
23 fprintf(stderr
, "run_fn starting\n");
25 rc
= pthread_mutex_lock(&mutex
);
30 fprintf(stderr
, "run_fn(): status==0\n");
31 rc
= pthread_cond_wait(&cond_var
, &mutex
);
34 fprintf(stderr
, "run_fn(): woke up\n");
37 fprintf(stderr
, "run_fn(): status==1\n");
39 rc
= pthread_mutex_unlock(&mutex
);
43 fprintf(stderr
, "run_fn done\n");
48 int main(int argc
, char **argv
)
51 pthread_t other_thread
;
56 rc
= pthread_mutex_init(&mutex
, NULL
);
58 rc
= pthread_cond_init(&cond_var
, NULL
);
63 rc
= pthread_create(&other_thread
, NULL
, run_fn
, NULL
);
66 /* yield the processor, and give the other thread a chance to get into the while loop */
68 fprintf(stderr
, "main(): sleeping...\n");
71 rc
= pthread_mutex_lock(&mutex
);
76 fprintf(stderr
, "main(): status=1\n");
78 rc
= pthread_cond_broadcast(&cond_var
);
82 rc
= pthread_mutex_unlock(&mutex
);
86 fprintf(stderr
, "joining...\n");
88 rc
= pthread_join(other_thread
, NULL
);
91 fprintf(stderr
, "Done.\n");