source: CIVL/examples/pthread/esbmc/stack_false-unreach-call.c@ beab7f2

main test-branch
Last change on this file since beab7f2 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.6 KB
Line 
1extern void __VERIFIER_error();
2
3#include <pthread.h>
4#include <stdio.h>
5
6#define TRUE (1)
7#define FALSE (0)
8#define SIZE (5)
9#define OVERFLOW (-1)
10#define UNDERFLOW (-2)
11
12unsigned int __VERIFIER_nondet_uint();
13static int top=0;
14static unsigned int arr[SIZE];
15pthread_mutex_t m;
16_Bool flag=FALSE;
17
18void error(void)
19{
20 ERROR: __VERIFIER_error();
21 return;
22}
23
24void inc_top(void)
25{
26 top++;
27}
28
29void dec_top(void)
30{
31 top--;
32}
33
34int get_top(void)
35{
36 return top;
37}
38
39int stack_empty(void)
40{
41 (top==0) ? TRUE : FALSE;
42}
43
44int push(unsigned int *stack, int x)
45{
46 if (top==SIZE)
47 {
48 printf("stack overflow\n");
49 return OVERFLOW;
50 }
51 else
52 {
53 stack[get_top()] = x;
54 inc_top();
55 }
56 return 0;
57}
58
59int pop(unsigned int *stack)
60{
61 if (get_top()==0)
62 {
63 printf("stack underflow\n");
64 return UNDERFLOW;
65 }
66 else
67 {
68 dec_top();
69 return stack[get_top()];
70 }
71 return 0;
72}
73
74void *t1(void *arg)
75{
76 int i;
77 unsigned int tmp;
78
79 for(i=0; i<SIZE; i++)
80 {
81 pthread_mutex_lock(&m);
82 tmp = __VERIFIER_nondet_uint()%SIZE;
83 if (push(arr,tmp)==OVERFLOW)
84 error();
85 flag=TRUE;
86 pthread_mutex_unlock(&m);
87 }
88}
89
90void *t2(void *arg)
91{
92 int i;
93
94 for(i=0; i<SIZE; i++)
95 {
96 pthread_mutex_lock(&m);
97 if (flag)
98 {
99 if (!(pop(arr)!=UNDERFLOW))
100 error();
101 }
102 pthread_mutex_unlock(&m);
103 }
104}
105
106
107int main(void)
108{
109 pthread_t id1, id2;
110
111 pthread_mutex_init(&m, 0);
112
113 pthread_create(&id1, NULL, t1, NULL);
114 pthread_create(&id2, NULL, t2, NULL);
115
116 pthread_join(id1, NULL);
117 pthread_join(id2, NULL);
118
119 return 0;
120}
121
Note: See TracBrowser for help on using the repository browser.