Eager update predicate trees rather than lazy update; under construction
[c11tester.git] / pthread_test / deadlock.cc
1 #include <stdio.h>
2 #include <pthread.h>
3
4 #include "librace.h"
5
6 pthread_mutex_t x;
7 pthread_mutex_t y;
8 uint32_t shared = 0;
9
10 static void *a(void *obj)
11 {
12         pthread_mutex_lock(&x);
13         pthread_mutex_lock(&y);
14         printf("shared = %u\n", load_32(&shared));
15         pthread_mutex_unlock(&y);
16         pthread_mutex_unlock(&x);
17         return NULL;
18 }
19
20 static void *b(void *obj)
21 {
22         pthread_mutex_lock(&y);
23         pthread_mutex_lock(&x);
24         store_32(&shared, 16);
25         printf("write shared = 16\n");
26         pthread_mutex_unlock(&x);
27         pthread_mutex_unlock(&y);
28         return NULL;
29 }
30
31 int user_main(int argc, char **argv)
32 {
33         pthread_t t1, t2;
34
35         pthread_mutex_init(&x, NULL);
36         pthread_mutex_init(&y, NULL);
37
38         printf("Main thread: creating 2 threads\n");
39         pthread_create(&t1,NULL, &a, NULL);
40         pthread_create(&t2,NULL, &b, NULL);
41
42         pthread_join(t1,NULL);
43         pthread_join(t2,NULL);
44         printf("Main thread is finished\n");
45
46         return 0;
47 }