1.23
2.0
main
test-branch
| 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;
|
|---|
| 20 | int OVERFLOW = -1;
|
|---|
| 21 | int UNDERFLOW = -2;
|
|---|
| 22 |
|
|---|
| 23 | int top = 0;
|
|---|
| 24 | unsigned int arr[SIZE];
|
|---|
| 25 | pthread_mutex_t m;
|
|---|
| 26 | _Bool flag=$false;
|
|---|
| 27 |
|
|---|
| 28 | void error(void)
|
|---|
| 29 | {
|
|---|
| 30 | $assert($false);
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | void inc_top(void)
|
|---|
| 34 | {
|
|---|
| 35 | top++;
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | void dec_top(void)
|
|---|
| 39 | {
|
|---|
| 40 | top--;
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | int get_top(void)
|
|---|
| 44 | {
|
|---|
| 45 | return top;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | int stack_empty(void)
|
|---|
| 49 | {
|
|---|
| 50 | (top==0) ? TRUE : FALSE;
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | int 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 |
|
|---|
| 68 | int 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 |
|
|---|
| 83 | void *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 |
|
|---|
| 101 | void *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 |
|
|---|
| 119 | void 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.