main
test-branch
|
Last change
on this file since bd7a43e 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.5 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 (400)
|
|---|
| 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 | { ERROR: __VERIFIER_error(); return;
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | void inc_top(void)
|
|---|
| 22 | {
|
|---|
| 23 | top++;
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | void dec_top(void)
|
|---|
| 27 | {
|
|---|
| 28 | top--;
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | int get_top(void)
|
|---|
| 32 | {
|
|---|
| 33 | return top;
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | int stack_empty(void)
|
|---|
| 37 | {
|
|---|
| 38 | (top==0) ? TRUE : FALSE;
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | int push(unsigned int *stack, int x)
|
|---|
| 42 | {
|
|---|
| 43 | if (top==SIZE)
|
|---|
| 44 | {
|
|---|
| 45 | printf("stack overflow\n");
|
|---|
| 46 | return OVERFLOW;
|
|---|
| 47 | }
|
|---|
| 48 | else
|
|---|
| 49 | {
|
|---|
| 50 | stack[get_top()] = x;
|
|---|
| 51 | inc_top();
|
|---|
| 52 | }
|
|---|
| 53 | return 0;
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | int pop(unsigned int *stack)
|
|---|
| 57 | {
|
|---|
| 58 | if (get_top()==0)
|
|---|
| 59 | {
|
|---|
| 60 | printf("stack underflow\n");
|
|---|
| 61 | return UNDERFLOW;
|
|---|
| 62 | }
|
|---|
| 63 | else
|
|---|
| 64 | {
|
|---|
| 65 | dec_top();
|
|---|
| 66 | return stack[get_top()];
|
|---|
| 67 | }
|
|---|
| 68 | return 0;
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | void *t1(void *arg)
|
|---|
| 72 | {
|
|---|
| 73 | int i;
|
|---|
| 74 | unsigned int tmp;
|
|---|
| 75 |
|
|---|
| 76 | for(i=0; i<SIZE; i++)
|
|---|
| 77 | {
|
|---|
| 78 | pthread_mutex_lock(&m);
|
|---|
| 79 | tmp = __VERIFIER_nondet_uint()%SIZE;
|
|---|
| 80 | if (push(arr,tmp)==OVERFLOW)
|
|---|
| 81 | error();
|
|---|
| 82 | flag=TRUE;
|
|---|
| 83 | pthread_mutex_unlock(&m);
|
|---|
| 84 | }
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | void *t2(void *arg)
|
|---|
| 88 | {
|
|---|
| 89 | int i;
|
|---|
| 90 |
|
|---|
| 91 | for(i=0; i<SIZE; i++)
|
|---|
| 92 | {
|
|---|
| 93 | pthread_mutex_lock(&m);
|
|---|
| 94 | if (flag)
|
|---|
| 95 | {
|
|---|
| 96 | if (!(pop(arr)!=UNDERFLOW))
|
|---|
| 97 | error();
|
|---|
| 98 | }
|
|---|
| 99 | pthread_mutex_unlock(&m);
|
|---|
| 100 | }
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 | int main(void)
|
|---|
| 105 | {
|
|---|
| 106 | pthread_t id1, id2;
|
|---|
| 107 |
|
|---|
| 108 | pthread_mutex_init(&m, 0);
|
|---|
| 109 |
|
|---|
| 110 | pthread_create(&id1, NULL, t1, NULL);
|
|---|
| 111 | pthread_create(&id2, NULL, t2, NULL);
|
|---|
| 112 |
|
|---|
| 113 | pthread_join(id1, NULL);
|
|---|
| 114 | pthread_join(id2, NULL);
|
|---|
| 115 |
|
|---|
| 116 | return 0;
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.