drd/tests/Makefile.am: Add dlopen.stdout.exp to EXTRA_DIST
[valgrind.git] / helgrind / tests / hg02_deadlock.c
blob1142f5cfe9a025dbcf7de2e31635704e06bb9b65
1 /* Simple possible deadlock */
2 #include <pthread.h>
4 static pthread_mutex_t m1 = PTHREAD_MUTEX_INITIALIZER;
5 static pthread_mutex_t m2 = PTHREAD_MUTEX_INITIALIZER;
7 static void *t1(void *v)
9 pthread_mutex_lock(&m1);
10 pthread_mutex_lock(&m2);
11 pthread_mutex_unlock(&m1);
12 pthread_mutex_unlock(&m2);
14 return 0;
17 static void *t2(void *v)
19 pthread_mutex_lock(&m2);
20 pthread_mutex_lock(&m1);
21 pthread_mutex_unlock(&m1);
22 pthread_mutex_unlock(&m2);
24 return 0;
27 int main()
29 pthread_t a, b;
31 /* prevent spurious messages from the dynamic linker */
32 pthread_mutex_lock(&m1);
33 pthread_mutex_unlock(&m1);
35 pthread_create(&a, NULL, t1, NULL);
36 pthread_create(&b, NULL, t2, NULL);
38 pthread_join(a, NULL);
39 pthread_join(b, NULL);
41 return 0;