source: CIVL/examples/pthread/stack_false.cvl@ 325d439

1.23 2.0 main test-branch
Last change on this file since 325d439 was 38374b7, checked in by John Edenhofner <johneden@…>, 12 years ago

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

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/**
2* This is a translation of a Pthread program from
3* the Pthread benchmarks of SV-COMP 2014.
4* https://svn.sosy-lab.org/software/sv-benchmarks/tags/svcomp14/
5*
6* Command line execution:
7* civl verify -inputSIZE=8 stack_false.cvl -min
8*/
9
10#include <civlc.h>
11#include "pthread.cvh"
12#include <stdio.h>
13#include <assert.h>
14#include <stdlib.h>
15
16$input int SIZE;
17
18_Bool TRUE = 1;
19_Bool FALSE = 0;
20int OVERFLOW = -1;
21int UNDERFLOW = -2;
22
23int top = 0;
24unsigned int arr[SIZE];
25pthread_mutex_t m;
26_Bool flag=$false;
27
28void error(void)
29{
30 $assert($false);
31}
32
33void inc_top(void)
34{
35 top++;
36}
37
38void dec_top(void)
39{
40 top--;
41}
42
43int get_top(void)
44{
45 return top;
46}
47
48int stack_empty(void)
49{
50 (top==0) ? TRUE : FALSE;
51}
52
53int push(unsigned int *stack, int x)
54{
55 if (top==SIZE)
56 {
57 printf("stack overflow\n");
58 return OVERFLOW;
59 }
60 else
61 {
62 stack[get_top()] = x;
63 inc_top();
64 }
65 return 0;
66}
67
68int pop(unsigned int *stack)
69{
70 if (get_top()==0)
71 {
72 printf("stack underflow\n");
73 return UNDERFLOW;
74 }
75 else
76 {
77 dec_top();
78 return stack[get_top()];
79 }
80 return 0;
81}
82
83void *t1(void*arg)
84{
85 int i;
86 unsigned int tmp;
87
88 for(i=0; i<SIZE; i++)
89 {
90 pthread_mutex_lock(&m);
91 tmp = 1;
92 tmp = tmp % 5;
93 int tmp1 = push(arr,tmp);
94 if (tmp1==OVERFLOW)
95 error();
96 flag=TRUE;
97 pthread_mutex_unlock(&m);
98 }
99}
100
101void *t2(void*arg)
102{
103 int i;
104
105 for(i=0; i<SIZE; i++)
106 {
107 pthread_mutex_lock(&m);
108 if (flag)
109 {
110 int tmp = pop(arr);
111 if (!(tmp)!=UNDERFLOW)
112 error();
113 }
114 pthread_mutex_unlock(&m);
115 }
116}
117
118
119void main()
120{
121 pthread_t id1, id2;
122
123 pthread_mutex_init(&m, 0);
124
125 pthread_create(&id1, NULL, t1, NULL);
126 pthread_create(&id2, NULL, t2, NULL);
127
128 pthread_join(id1, NULL);
129 pthread_join(id2, NULL);
130}
Note: See TracBrowser for help on using the repository browser.