execution: add const
[model-checker.git] / test / condvar.cc
1 #include <stdio.h>
2
3 #include "threads.h"
4 #include "librace.h"
5 #include "stdatomic.h"
6 #include <mutex>
7 #include <condition_variable>
8
9 std::mutex * m;
10 std::condition_variable *v;
11 int shareddata;
12
13 static void a(void *obj)
14 {
15         
16         m->lock();
17         while(load_32(&shareddata)==0)
18                 v->wait(*m);
19         m->unlock();
20
21 }
22
23 static void b(void *obj)
24 {
25         m->lock();
26         store_32(&shareddata, (unsigned int) 1);
27         v->notify_all();
28         m->unlock();
29 }
30
31 int user_main(int argc, char **argv)
32 {
33         thrd_t t1, t2;
34         store_32(&shareddata, (unsigned int) 0);
35         m=new std::mutex();
36         v=new std::condition_variable();
37
38         thrd_create(&t1, (thrd_start_t)&a, NULL);
39         thrd_create(&t2, (thrd_start_t)&b, NULL);
40
41         thrd_join(t1);
42         thrd_join(t2);
43         return 0;
44 }