main
test-branch
|
Last change
on this file since beab7f2 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago |
|
Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.
git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c
|
-
Property mode
set to
100644
|
|
File size:
1.6 KB
|
| Line | |
|---|
| 1 | extern void __VERIFIER_error() ;
|
|---|
| 2 | #include <pthread.h>
|
|---|
| 3 | #include <stdio.h>
|
|---|
| 4 |
|
|---|
| 5 | #define TRUE (1)
|
|---|
| 6 | #define FALSE (0)
|
|---|
| 7 | #define SIZE (800)
|
|---|
| 8 | #define OVERFLOW (-1)
|
|---|
| 9 | #define UNDERFLOW (-2)
|
|---|
| 10 |
|
|---|
| 11 | unsigned int __VERIFIER_nondet_uint();
|
|---|
| 12 | static int top=0;
|
|---|
| 13 | static unsigned int arr[SIZE];
|
|---|
| 14 | pthread_mutex_t m;
|
|---|
| 15 | _Bool flag=FALSE;
|
|---|
| 16 |
|
|---|
| 17 | void error(void)
|
|---|
| 18 | {
|
|---|
| 19 | ERROR: __VERIFIER_error(); return;
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | void inc_top(void)
|
|---|
| 23 | {
|
|---|
| 24 | top++;
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | void dec_top(void)
|
|---|
| 28 | {
|
|---|
| 29 | top--;
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | int get_top(void)
|
|---|
| 33 | {
|
|---|
| 34 | return top;
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | int stack_empty(void)
|
|---|
| 38 | {
|
|---|
| 39 | (top==0) ? TRUE : FALSE;
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | int push(unsigned int *stack, int x)
|
|---|
| 43 | {
|
|---|
| 44 | if (top==SIZE)
|
|---|
| 45 | {
|
|---|
| 46 | printf("stack overflow\n");
|
|---|
| 47 | return OVERFLOW;
|
|---|
| 48 | }
|
|---|
| 49 | else
|
|---|
| 50 | {
|
|---|
| 51 | stack[get_top()] = x;
|
|---|
| 52 | inc_top();
|
|---|
| 53 | }
|
|---|
| 54 | return 0;
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | int pop(unsigned int *stack)
|
|---|
| 58 | {
|
|---|
| 59 | if (get_top()==0)
|
|---|
| 60 | {
|
|---|
| 61 | printf("stack underflow\n");
|
|---|
| 62 | return UNDERFLOW;
|
|---|
| 63 | }
|
|---|
| 64 | else
|
|---|
| 65 | {
|
|---|
| 66 | dec_top();
|
|---|
| 67 | return stack[get_top()];
|
|---|
| 68 | }
|
|---|
| 69 | return 0;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | void *t1(void *arg)
|
|---|
| 73 | {
|
|---|
| 74 | int i;
|
|---|
| 75 | unsigned int tmp;
|
|---|
| 76 |
|
|---|
| 77 | for(i=0; i<SIZE; i++)
|
|---|
| 78 | {
|
|---|
| 79 | pthread_mutex_lock(&m);
|
|---|
| 80 | tmp = __VERIFIER_nondet_uint()%SIZE;
|
|---|
| 81 | if (push(arr,tmp)==OVERFLOW)
|
|---|
| 82 | error();
|
|---|
| 83 | flag=TRUE;
|
|---|
| 84 | pthread_mutex_unlock(&m);
|
|---|
| 85 | }
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | void *t2(void *arg)
|
|---|
| 89 | {
|
|---|
| 90 | int i;
|
|---|
| 91 |
|
|---|
| 92 | for(i=0; i<SIZE; i++)
|
|---|
| 93 | {
|
|---|
| 94 | pthread_mutex_lock(&m);
|
|---|
| 95 | if (flag)
|
|---|
| 96 | {
|
|---|
| 97 | if (!(pop(arr)!=UNDERFLOW))
|
|---|
| 98 | error();
|
|---|
| 99 | }
|
|---|
| 100 | pthread_mutex_unlock(&m);
|
|---|
| 101 | }
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 | int main(void)
|
|---|
| 106 | {
|
|---|
| 107 | pthread_t id1, id2;
|
|---|
| 108 |
|
|---|
| 109 | pthread_mutex_init(&m, 0);
|
|---|
| 110 |
|
|---|
| 111 | pthread_create(&id1, NULL, t1, NULL);
|
|---|
| 112 | pthread_create(&id2, NULL, t2, NULL);
|
|---|
| 113 |
|
|---|
| 114 | pthread_join(id1, NULL);
|
|---|
| 115 | pthread_join(id2, NULL);
|
|---|
| 116 |
|
|---|
| 117 | return 0;
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.