drd/tests/Makefile.am: Add dlopen.stdout.exp to EXTRA_DIST
[valgrind.git] / helgrind / tests / pth_destroy_cond.c
blob54f4f433c7187d3e11bb303e16ac8d2bfc6f0209
1 #include <stdio.h>
2 #include <pthread.h>
3 #include <errno.h>
4 // test program from johan.walles (bug 295590)
5 // This test verifies that helgrind detects (and does not crash) when
6 // the guest application wrongly destroys a cond var being waited
7 // upon.
8 pthread_mutex_t mutex;
9 pthread_cond_t cond;
10 pthread_t thread;
11 int ready = 0;
13 void *ThreadFunction(void *ptr)
15 pthread_mutex_lock(&mutex);
16 ready = 1;
17 pthread_cond_signal(&cond);
18 pthread_cond_destroy(&cond); // ERROR!!!
19 pthread_mutex_unlock(&mutex);
20 return NULL;
23 int main()
25 pthread_mutex_init(&mutex, NULL);
26 pthread_cond_init(&cond, NULL);
28 pthread_mutex_lock(&mutex);
29 pthread_create(&thread, NULL, ThreadFunction, (void*) NULL);
30 while (!ready) { // to insure ourselves against spurious wakeups
31 pthread_cond_wait(&cond, &mutex);
33 pthread_mutex_unlock(&mutex);
35 pthread_join(thread, NULL);
36 pthread_mutex_destroy(&mutex);
37 printf("finished\n");
38 return 0;