source: CIVL/examples/translation/pthread/stack_true.cvl@ 50f834b

1.23 2.0 main test-branch
Last change on this file since 50f834b was bf46837, checked in by Manchun Zheng <zmanchun@…>, 12 years ago

added comments.

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

  • Property mode set to 100755
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}
97
98void *t2(void*arg)
99{
100 int i;
101
102 for(i=0; i<SIZE; i++)
103 {
104 pthread_mutex_lock(&m);
105 if (top>0)
106 {
107 int tmp = pop(arr);
108 if (tmp==UNDERFLOW)
109 error();
110 }
111 pthread_mutex_unlock(&m);
112 }
113}
114
115
116void main()
117{
118 pthread_t id1, id2;
119
120 pthread_mutex_init(&m, 0);
121
122 pthread_create(&id1, NULL, t1, NULL);
123 pthread_create(&id2, NULL, t2, NULL);
124
125 pthread_join(id1, NULL);
126 pthread_join(id2, NULL);
127}
Note: See TracBrowser for help on using the repository browser.