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