main
test-branch
|
Last change
on this file since 1aaefd4 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago |
|
Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.
git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c
|
-
Property mode
set to
100644
|
|
File size:
855 bytes
|
| Line | |
|---|
| 1 | extern void __VERIFIER_error();
|
|---|
| 2 |
|
|---|
| 3 | #include <stdio.h>
|
|---|
| 4 | #include <pthread.h>
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 | int num;
|
|---|
| 8 |
|
|---|
| 9 | pthread_mutex_t m;
|
|---|
| 10 | pthread_cond_t empty, full;
|
|---|
| 11 |
|
|---|
| 12 | void * thread1(void * arg)
|
|---|
| 13 | {
|
|---|
| 14 | pthread_mutex_lock(&m);
|
|---|
| 15 |
|
|---|
| 16 | while (num > 0)
|
|---|
| 17 | pthread_cond_wait(&empty, &m);
|
|---|
| 18 |
|
|---|
| 19 | num++;
|
|---|
| 20 |
|
|---|
| 21 | pthread_mutex_unlock(&m);
|
|---|
| 22 | pthread_cond_signal(&full);
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 | void * thread2(void * arg)
|
|---|
| 27 | {
|
|---|
| 28 | pthread_mutex_lock(&m);
|
|---|
| 29 |
|
|---|
| 30 | while (num == 0)
|
|---|
| 31 | pthread_cond_wait(&full, &m);
|
|---|
| 32 |
|
|---|
| 33 | num--;
|
|---|
| 34 |
|
|---|
| 35 | pthread_mutex_unlock(&m);
|
|---|
| 36 |
|
|---|
| 37 | pthread_cond_signal(&empty);
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 | int main()
|
|---|
| 42 | {
|
|---|
| 43 | pthread_t t1, t2;
|
|---|
| 44 |
|
|---|
| 45 | num = 1;
|
|---|
| 46 |
|
|---|
| 47 | pthread_mutex_init(&m, 0);
|
|---|
| 48 | pthread_cond_init(&empty, 0);
|
|---|
| 49 | pthread_cond_init(&full, 0);
|
|---|
| 50 |
|
|---|
| 51 | pthread_create(&t1, 0, thread1, 0);
|
|---|
| 52 | pthread_create(&t2, 0, thread2, 0);
|
|---|
| 53 |
|
|---|
| 54 | pthread_join(t1, 0);
|
|---|
| 55 | pthread_join(t2, 0);
|
|---|
| 56 |
|
|---|
| 57 | if (num!=1)
|
|---|
| 58 | {
|
|---|
| 59 | ERROR: __VERIFIER_error();
|
|---|
| 60 | ;
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | return 0;
|
|---|
| 64 |
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.