1.23
2.0
acw/focus-triggers
main
test-branch
| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * Command line execution:
|
|---|
| 3 | * civl verify stateful01_true.cvl
|
|---|
| 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 |
|
|---|
| 24 | void *thread2(void*arg)
|
|---|
| 25 | {
|
|---|
| 26 | pthread_mutex_lock(&ma);
|
|---|
| 27 | data1+=5;
|
|---|
| 28 | pthread_mutex_unlock(&ma);
|
|---|
| 29 |
|
|---|
| 30 | pthread_mutex_lock(&ma);
|
|---|
| 31 | data2-=6;
|
|---|
| 32 | pthread_mutex_unlock(&ma);
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 | void main()
|
|---|
| 37 | {
|
|---|
| 38 | pthread_t t1, t2;
|
|---|
| 39 |
|
|---|
| 40 | pthread_mutex_init(&ma, 0);
|
|---|
| 41 | pthread_mutex_init(&mb, 0);
|
|---|
| 42 |
|
|---|
| 43 | data1 = 10;
|
|---|
| 44 | data2 = 10;
|
|---|
| 45 |
|
|---|
| 46 | pthread_create(&t1, 0, thread1, 0);
|
|---|
| 47 | pthread_create(&t2, 0, thread2, 0);
|
|---|
| 48 |
|
|---|
| 49 | pthread_join(t1, 0);
|
|---|
| 50 | pthread_join(t2, 0);
|
|---|
| 51 |
|
|---|
| 52 | if (data1!=16 && data2!=5)
|
|---|
| 53 | {
|
|---|
| 54 | $assert($false);
|
|---|
| 55 | }
|
|---|
| 56 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.