edist
[cdsspec-compiler.git] / output / mcs-lock / mcs-lock.cc
1 #include <stdio.h>
2 #include <threads.h>
3
4 #include "mcs-lock.h"
5
6
7 #include "librace.h"
8
9 struct mcs_mutex *mutex;
10 static uint32_t shared;
11
12 void threadA(void *arg)
13 {
14         mcs_mutex::guard g(mutex);
15                         shared = 17;
16         mutex->unlock(&g);
17         mutex->lock(&g);
18                 }
19
20 void threadB(void *arg)
21 {
22         mcs_mutex::guard g(mutex);
23                         mutex->unlock(&g);
24         mutex->lock(&g);
25                 shared = 17;
26         }
27
28 int user_main(int argc, char **argv)
29 {
30         thrd_t A, B;
31
32         mutex = new mcs_mutex();
33
34         thrd_create(&A, &threadA, NULL);
35         thrd_create(&B, &threadB, NULL);
36         thrd_join(A);
37         thrd_join(B);
38         return 0;
39 }
40