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