source: CIVL/examples/pthread/cprover/25_stack_true.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.8 KB
Line 
1//original file: EBStack.java
2//amino-cbbs\trunk\amino\java\src\main\java\org\amino\ds\lockfree
3//push only
4
5#include <pthread.h>
6
7#define assume(e) __VERIFIER_assume(e)
8#define assert(e) { if(!(e)) { ERROR: goto ERROR; (void)0; } }
9
10void __VERIFIER_atomic_acquire(int * m)
11{
12 assume(*m==0);
13 *m = 1;
14}
15
16void __VERIFIER_atomic_release(int * m)
17{
18 assume(*m==1);
19 *m = 0;
20}
21
22#define MEMSIZE (2*32+1) //0 for "NULL"
23int memory[MEMSIZE];
24#define INDIR(cell,idx) memory[cell+idx]
25
26int next_alloc_idx = 1;
27int m = 0;
28int top;
29
30inline int index_malloc(){
31 int curr_alloc_idx = -1;
32
33 __VERIFIER_atomic_acquire(&m);
34 if(next_alloc_idx+2-1 > MEMSIZE){
35 __VERIFIER_atomic_release(&m);
36 curr_alloc_idx = 0;
37 }else{
38 curr_alloc_idx = next_alloc_idx;
39 next_alloc_idx += 2;
40 __VERIFIER_atomic_release(&m);
41 }
42
43 return curr_alloc_idx;
44}
45
46inline void EBStack_init(){
47 top = 0;
48}
49
50inline int isEmpty() {
51 if(top == 0)
52 return 1;
53 else
54 return 0;
55}
56
57inline int push(int d) {
58 int oldTop = -1, newTop = -1;
59
60 newTop = index_malloc();
61 if(newTop == 0){
62 return 0;
63 }else{
64 INDIR(newTop,0) = d;
65
66 __VERIFIER_atomic_acquire(&m);
67 oldTop = top;
68 INDIR(newTop,1) = oldTop;
69 top = newTop;
70 __VERIFIER_atomic_release(&m);
71 return 1;
72 }
73}
74
75inline void init(){
76 EBStack_init();
77}
78
79void __VERIFIER_atomic_assert(int r)
80{
81 assert(!r || !isEmpty());
82}
83
84inline void push_loop(){
85 int r = -1;
86 int arg = __VERIFIER_nondet_int();
87 while(1){
88 r = push(arg);
89 __VERIFIER_atomic_assert(r);
90 }
91}
92
93int m2 = 0;
94int state = 0;
95void* thr1(void* arg)
96{
97 __VERIFIER_atomic_acquire(&m2);
98 switch(state)
99 {
100 case 0:
101 EBStack_init();
102 state = 1;
103 //fall-through
104 case 1:
105 __VERIFIER_atomic_release(&m2);
106
107 push_loop();
108 break;
109 }
110
111 return 0;
112}
113
114int main()
115{
116 pthread_t t;
117
118 while(1) { pthread_create(&t, 0, thr1, 0); }
119}
120
Note: See TracBrowser for help on using the repository browser.