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 sync01_true.cvl
|
|---|
| 8 | */
|
|---|
| 9 |
|
|---|
| 10 | #include <civlc.h>
|
|---|
| 11 | #include "pthread.cvh"
|
|---|
| 12 |
|
|---|
| 13 | int num;
|
|---|
| 14 | pthread_mutex_t m;
|
|---|
| 15 | pthread_cond_t empty, full;
|
|---|
| 16 |
|
|---|
| 17 | void *thread1(void*arg)
|
|---|
| 18 | {
|
|---|
| 19 | pthread_mutex_lock(&m);
|
|---|
| 20 |
|
|---|
| 21 | while (num > 0)
|
|---|
| 22 | pthread_cond_wait(&empty, &m);
|
|---|
| 23 |
|
|---|
| 24 | num++;
|
|---|
| 25 |
|
|---|
| 26 | pthread_mutex_unlock(&m);
|
|---|
| 27 | pthread_cond_signal(&full);
|
|---|
| 28 | return NULL;
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 | void *thread2(void*arg)
|
|---|
| 33 | {
|
|---|
| 34 | pthread_mutex_lock(&m);
|
|---|
| 35 |
|
|---|
| 36 | while (num == 0)
|
|---|
| 37 | pthread_cond_wait(&full, &m);
|
|---|
| 38 |
|
|---|
| 39 | num--;
|
|---|
| 40 |
|
|---|
| 41 | pthread_mutex_unlock(&m);
|
|---|
| 42 |
|
|---|
| 43 | pthread_cond_signal(&empty);
|
|---|
| 44 |
|
|---|
| 45 | return NULL;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 | void main()
|
|---|
| 50 | {
|
|---|
| 51 | pthread_t t1, t2;
|
|---|
| 52 |
|
|---|
| 53 | num = 1;
|
|---|
| 54 |
|
|---|
| 55 | pthread_mutex_init(&m, 0);
|
|---|
| 56 | pthread_cond_init(&empty, NULL);
|
|---|
| 57 | pthread_cond_init(&full, NULL);
|
|---|
| 58 |
|
|---|
| 59 | pthread_create(&t1, 0, thread1, 0);
|
|---|
| 60 | pthread_create(&t2, 0, thread2, 0);
|
|---|
| 61 |
|
|---|
| 62 | pthread_join(t1, 0);
|
|---|
| 63 | pthread_join(t2, 0);
|
|---|
| 64 |
|
|---|
| 65 | if (num!=1)
|
|---|
| 66 | {
|
|---|
| 67 | $assert($false);
|
|---|
| 68 | }
|
|---|
| 69 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.