mcs-lock: write proper driver
[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         mutex->lock(&g);
16         printf("store: %d\n", 17);
17         store_32(&shared, 17);
18         mutex->unlock(&g);
19 }
20
21 void threadB(void *arg)
22 {
23         mcs_mutex::guard g(mutex);
24         mutex->lock(&g);
25         printf("load: %u\n", load_32(&shared));
26         mutex->unlock(&g);
27 }
28
29 int user_main(int argc, char **argv)
30 {
31         thrd_t A, B;
32
33         mutex = new mcs_mutex();
34
35         thrd_create(&A, &threadA, NULL);
36         thrd_create(&B, &threadB, NULL);
37         thrd_join(A);
38         thrd_join(B);
39         return 0;
40 }