Add DRD suppression patterns for races triggered by std::ostream
[valgrind.git] / drd / tests / bug-235681.c
blob99114eb6bfbf23f2c0a1b9ef05d7c9263dfe77f8
1 /*
2 * pthread_cond_wait() test program.
3 * See also https://bugs.kde.org/show_bug.cgi?id=235681.
4 */
6 #include <string.h>
7 #include <stdio.h>
8 #include <assert.h>
9 #include <pthread.h>
10 #include <errno.h>
11 #include <unistd.h>
13 pthread_mutex_t mutex;
14 pthread_cond_t cond_var;
15 int status;
16 int silent;
18 static void *run_fn(void *v)
20 int rc;
22 if (!silent)
23 fprintf(stderr, "run_fn starting\n");
25 rc = pthread_mutex_lock(&mutex);
26 assert(!rc);
28 while (!status) {
29 if (!silent)
30 fprintf(stderr, "run_fn(): status==0\n");
31 rc = pthread_cond_wait(&cond_var, &mutex);
32 assert(!rc);
33 if (!silent)
34 fprintf(stderr, "run_fn(): woke up\n");
36 if (!silent)
37 fprintf(stderr, "run_fn(): status==1\n");
39 rc = pthread_mutex_unlock(&mutex);
40 assert(!rc);
42 if (!silent)
43 fprintf(stderr, "run_fn done\n");
45 return NULL;
48 int main(int argc, char **argv)
50 int rc;
51 pthread_t other_thread;
53 if (argc > 1)
54 silent = 1;
56 rc = pthread_mutex_init(&mutex, NULL);
57 assert(!rc);
58 rc = pthread_cond_init(&cond_var, NULL);
59 assert(!rc);
61 status = 0;
63 rc = pthread_create(&other_thread, NULL, run_fn, NULL);
64 assert(!rc);
66 /* yield the processor, and give the other thread a chance to get into the while loop */
67 if (!silent)
68 fprintf(stderr, "main(): sleeping...\n");
69 sleep(1);
71 rc = pthread_mutex_lock(&mutex);
72 assert(!rc);
73 /**** BEGIN CS *****/
75 if (!silent)
76 fprintf(stderr, "main(): status=1\n");
77 status = 1;
78 rc = pthread_cond_broadcast(&cond_var);
79 assert(!rc);
81 /**** END CS *****/
82 rc = pthread_mutex_unlock(&mutex);
83 assert(!rc);
85 if (!silent)
86 fprintf(stderr, "joining...\n");
88 rc = pthread_join(other_thread, NULL);
89 assert(!rc);
91 fprintf(stderr, "Done.\n");
93 return 0;