source: CIVL/examples/pthread/cprover/32_pthread5_vs_false.c@ bb03188

main test-branch
Last change on this file since bb03188 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 1.1 KB
Line 
1#include <pthread.h>
2
3#define assume(e) __VERIFIER_assume(e)
4#define assert(e) { if(!(e)) { ERROR: goto ERROR; (void)0; } }
5
6#define MONITOR_EQ(x,y) \
7{ \
8 while(1) \
9 {\
10 __VERIFIER_atomic_acquire();\
11 assert(g0==g1);\
12 __VERIFIER_atomic_release();\
13 }\
14}
15
16int g0 = 0,g1 = 0,x = 0;
17_Bool lock = 0;
18int mutex = 0;
19
20void __VERIFIER_atomic_acquire()
21{
22 assume(mutex==0);
23 mutex = 1;
24}
25
26void __VERIFIER_atomic_release()
27{
28 assume(mutex==1);
29 mutex = 0;
30}
31
32void* thr3(void* arg)
33{
34
35 __VERIFIER_atomic_acquire();
36 if(__VERIFIER_nondet_int())
37 {
38 g0=0;
39 g1=0;
40 lock=0;
41 }
42 __VERIFIER_atomic_release();
43
44 __VERIFIER_atomic_acquire();
45 if(lock)
46 {
47 x=1;
48 assert(g0==1 && g1==1);
49 }
50 __VERIFIER_atomic_release();
51
52 return 0;
53}
54
55void* thr2(void* arg)
56{
57 MONITOR_EQ(g0,g1);
58
59 return 0;
60}
61
62void* thr1(void* arg)
63{
64 __VERIFIER_atomic_acquire();
65 g0=1,g1=1;
66 __VERIFIER_atomic_release();
67 lock=1;
68
69 return 0;
70}
71
72int main() {
73 pthread_t t;
74
75 pthread_create(&t, 0, thr1, 0);
76 pthread_create(&t, 0, thr2, 0);
77 while(1)
78 {
79 pthread_create(&t, 0, thr3, 0);
80 }
81}
82
Note: See TracBrowser for help on using the repository browser.