26e5a27edb76da058cc352eabd5c300a8fdb0ca8
[model-checker-benchmarks.git] / mcs-lock / mcs-lock.cc
1 #include <stdio.h>
2 #include <threads.h>
3
4 #include "mcs-lock.h"
5
6 /* For data race instrumentation */
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         printf("store: %d\n", 17);
16         store_32(&shared, 17);
17 }
18
19 void threadB(void *arg)
20 {
21         mcs_mutex::guard g(mutex);
22         printf("load: %u\n", load_32(&shared));
23 }
24
25 int user_main(int argc, char **argv)
26 {
27         thrd_t A, B;
28
29         mutex = new mcs_mutex();
30
31         thrd_create(&A, &threadA, NULL);
32         thrd_create(&B, &threadB, NULL);
33         thrd_join(A);
34         thrd_join(B);
35         return 0;
36 }