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 stateful01_true.cvl
|
|---|
| 8 | */
|
|---|
| 9 |
|
|---|
| 10 | #include <civlc.h>
|
|---|
| 11 | #include "pthread.cvh"
|
|---|
| 12 |
|
|---|
| 13 | pthread_mutex_t ma, mb;
|
|---|
| 14 | int data1, data2;
|
|---|
| 15 |
|
|---|
| 16 | void *thread1(void*arg)
|
|---|
| 17 | {
|
|---|
| 18 | pthread_mutex_lock(&ma);
|
|---|
| 19 | data1++;
|
|---|
| 20 | pthread_mutex_unlock(&ma);
|
|---|
| 21 |
|
|---|
| 22 | pthread_mutex_lock(&ma);
|
|---|
| 23 | data2++;
|
|---|
| 24 | pthread_mutex_unlock(&ma);
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 | void *thread2(void*arg)
|
|---|
| 29 | {
|
|---|
| 30 | pthread_mutex_lock(&ma);
|
|---|
| 31 | data1+=5;
|
|---|
| 32 | pthread_mutex_unlock(&ma);
|
|---|
| 33 |
|
|---|
| 34 | pthread_mutex_lock(&ma);
|
|---|
| 35 | data2-=6;
|
|---|
| 36 | pthread_mutex_unlock(&ma);
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 | void main()
|
|---|
| 41 | {
|
|---|
| 42 | pthread_t t1, t2;
|
|---|
| 43 |
|
|---|
| 44 | pthread_mutex_init(&ma, 0);
|
|---|
| 45 | pthread_mutex_init(&mb, 0);
|
|---|
| 46 |
|
|---|
| 47 | data1 = 10;
|
|---|
| 48 | data2 = 10;
|
|---|
| 49 |
|
|---|
| 50 | pthread_create(&t1, 0, thread1, 0);
|
|---|
| 51 | pthread_create(&t2, 0, thread2, 0);
|
|---|
| 52 |
|
|---|
| 53 | pthread_join(t1, 0);
|
|---|
| 54 | pthread_join(t2, 0);
|
|---|
| 55 |
|
|---|
| 56 | if (data1!=16 && data2!=5)
|
|---|
| 57 | {
|
|---|
| 58 | $assert($false);
|
|---|
| 59 | }
|
|---|
| 60 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.