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