1.23
2.0
acw/focus-triggers
main
test-branch
|
Last change
on this file since d87ec9c was 8d512ae, checked in by John Edenhofner <johneden@…>, 12 years ago |
|
Changed location of pthread.cvh, and updated files to use pthread.h (which includes pthread.cvh). New translations from pthread-atomic, and updated pthread.cvh
git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@1092 fb995dde-84ed-4084-dfe6-e5aef3e2452c
|
-
Property mode
set to
100644
|
|
File size:
936 bytes
|
| Line | |
|---|
| 1 | /* Testcase from Threader's distribution. For details see:
|
|---|
| 2 | http://www.model.in.tum.de/~popeea/research/threader
|
|---|
| 3 | */
|
|---|
| 4 |
|
|---|
| 5 | #include <pthread.h>
|
|---|
| 6 | #include <civlc.h>
|
|---|
| 7 | #define assert(e) if (!(e)) $assert($false);
|
|---|
| 8 |
|
|---|
| 9 | int flag1 = 0, flag2 = 0; // boolean flags
|
|---|
| 10 | int turn; // integer variable to hold the ID of the thread whose turn is it
|
|---|
| 11 | int x; // boolean variable to test mutual exclusion
|
|---|
| 12 |
|
|---|
| 13 | void *thr1(void *arg) {
|
|---|
| 14 | flag1 = 1;
|
|---|
| 15 | turn = 1;
|
|---|
| 16 | while (flag2==1 && turn==1) {};
|
|---|
| 17 | // begin: critical section
|
|---|
| 18 | x = 0;
|
|---|
| 19 | assert(x<=0);
|
|---|
| 20 | // end: critical section
|
|---|
| 21 | flag1 = 0;
|
|---|
| 22 | return NULL;
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | void *thr2(void *arg) {
|
|---|
| 26 | flag2 = 1;
|
|---|
| 27 | turn = 0;
|
|---|
| 28 | while (flag1==1 && turn==0) {};
|
|---|
| 29 | // begin: critical section
|
|---|
| 30 | x = 1;
|
|---|
| 31 | assert(x>=1);
|
|---|
| 32 | // end: critical section
|
|---|
| 33 | flag2 = 0;
|
|---|
| 34 | return NULL;
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | int main(void) {
|
|---|
| 38 | pthread_t t1, t2;
|
|---|
| 39 | pthread_create(&t1, 0, thr1, 0);
|
|---|
| 40 | pthread_create(&t2, 0, thr2, 0);
|
|---|
| 41 | pthread_join(t1, 0);
|
|---|
| 42 | pthread_join(t2, 0);
|
|---|
| 43 | return 0;
|
|---|
| 44 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.