source: CIVL/mods/dev.civl.abc/examples/svcomp/queue_ok_longest_true-unreach-call.c

main
Last change on this file was aad342c, checked in by Stephen Siegel <siegel@…>, 3 years ago

Performing huge refactor to incorporate ABC, GMC, and SARL into CIVL repo and use Java modules.

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

  • Property mode set to 100644
File size: 2.1 KB
Line 
1extern void __VERIFIER_error() __attribute__ ((__noreturn__));
2#include <pthread.h>
3#include <stdio.h>
4#include <assert.h>
5
6#define SIZE (800)
7#define EMPTY (-1)
8#define FULL (-2)
9#define FALSE (0)
10#define TRUE (1)
11
12typedef struct {
13 int element[SIZE];
14 int head;
15 int tail;
16 int amount;
17} QType;
18
19pthread_mutex_t m;
20int __VERIFIER_nondet_int();
21int stored_elements[SIZE];
22_Bool enqueue_flag, dequeue_flag;
23QType queue;
24
25int init(QType *q)
26{
27 q->head=0;
28 q->tail=0;
29 q->amount=0;
30}
31
32int empty(QType * q)
33{
34 if (q->head == q->tail)
35 {
36 printf("queue is empty\n");
37 return EMPTY;
38 }
39 else
40 return 0;
41}
42
43int full(QType * q)
44{
45 if (q->amount == SIZE)
46 {
47 printf("queue is full\n");
48 return FULL;
49 }
50 else
51 return 0;
52}
53
54int enqueue(QType *q, int x)
55{
56 q->element[q->tail] = x;
57 q->amount++;
58 if (q->tail == SIZE)
59 {
60 q->tail = 1;
61 }
62 else
63 {
64 q->tail++;
65 }
66
67 return 0;
68}
69
70int dequeue(QType *q)
71{
72 int x;
73
74 x = q->element[q->head];
75 q->amount--;
76 if (q->head == SIZE)
77 {
78 q->head = 1;
79 }
80 else
81 q->head++;
82
83 return x;
84}
85
86void *t1(void *arg)
87{
88 int value, i;
89
90 pthread_mutex_lock(&m);
91 if (enqueue_flag)
92 {
93 for(i=0; i<SIZE; i++)
94 {
95 value = __VERIFIER_nondet_int();
96 enqueue(&queue,value);
97 stored_elements[i]=value;
98 }
99 enqueue_flag=FALSE;
100 dequeue_flag=TRUE;
101 }
102 pthread_mutex_unlock(&m);
103
104 return NULL;
105}
106
107void *t2(void *arg)
108{
109 int i;
110
111 pthread_mutex_lock(&m);
112 if (dequeue_flag)
113 {
114 for(i=0; i<SIZE; i++)
115 {
116 if (empty(&queue)!=EMPTY)
117 if (!dequeue(&queue)==stored_elements[i]) {
118 ERROR:__VERIFIER_error();
119 }
120 }
121 dequeue_flag=FALSE;
122 enqueue_flag=TRUE;
123 }
124 pthread_mutex_unlock(&m);
125
126 return NULL;
127}
128
129int main(void)
130{
131 pthread_t id1, id2;
132
133 enqueue_flag=TRUE;
134 dequeue_flag=FALSE;
135
136 init(&queue);
137
138 if (!empty(&queue)==EMPTY) {
139 ERROR:__VERIFIER_error();
140 }
141
142 pthread_mutex_init(&m, 0);
143
144 pthread_create(&id1, NULL, t1, &queue);
145 pthread_create(&id2, NULL, t2, &queue);
146
147 pthread_join(id1, NULL);
148 pthread_join(id2, NULL);
149
150 return 0;
151}
152
Note: See TracBrowser for help on using the repository browser.