1.23
2.0
main
test-branch
| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * This program is taken from the Pthread benchmarks of SV-COMP 2014.
|
|---|
| 3 | * https://svn.sosy-lab.org/software/sv-benchmarks/tags/svcomp14/
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | #include <pthread.h>
|
|---|
| 7 |
|
|---|
| 8 | pthread_mutex_t ma, mb;
|
|---|
| 9 | int data1, data2;
|
|---|
| 10 |
|
|---|
| 11 | void * thread1(void * arg)
|
|---|
| 12 | {
|
|---|
| 13 | pthread_mutex_lock(&ma);
|
|---|
| 14 | data1++;
|
|---|
| 15 | pthread_mutex_unlock(&ma);
|
|---|
| 16 |
|
|---|
| 17 | pthread_mutex_lock(&ma);
|
|---|
| 18 | data2++;
|
|---|
| 19 | pthread_mutex_unlock(&ma);
|
|---|
| 20 | }
|
|---|
| 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 |
|
|---|
| 35 | int main()
|
|---|
| 36 | {
|
|---|
| 37 | pthread_t t1, t2;
|
|---|
| 38 |
|
|---|
| 39 | pthread_mutex_init(&ma, 0);
|
|---|
| 40 | pthread_mutex_init(&mb, 0);
|
|---|
| 41 |
|
|---|
| 42 | data1 = 10;
|
|---|
| 43 | data2 = 10;
|
|---|
| 44 |
|
|---|
| 45 | pthread_create(&t1, 0, thread1, 0);
|
|---|
| 46 | pthread_create(&t2, 0, thread2, 0);
|
|---|
| 47 |
|
|---|
| 48 | pthread_join(t1, 0);
|
|---|
| 49 | pthread_join(t2, 0);
|
|---|
| 50 |
|
|---|
| 51 | if (data1==16 && data2==5)
|
|---|
| 52 | {
|
|---|
| 53 | ERROR: goto ERROR;
|
|---|
| 54 | ;
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | return 0;
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.