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