source: CIVL/examples/translation/pthread/szymanski_true.cvl@ 4540352

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since 4540352 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: 1.1 KB
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
9int flag1 = 0, flag2 = 0; // integer flags
10int x; // boolean variable to test mutual exclusion
11
12void *thr1(void *arg) {
13 flag1 = 1;
14 while (flag2 >= 3);
15 flag1 = 3;
16 if (flag2 == 1) {
17 flag1 = 2;
18 while (flag2 != 4);
19 }
20 flag1 = 4;
21 while (flag2 >= 2);
22 // begin critical section
23 x = 0;
24 assert(x<=0);
25 // end critical section
26 while (2 <= flag2 && flag2 <= 3);
27 flag1 = 0;
28 return NULL;
29}
30
31void *thr2(void *arg) {
32 flag2 = 1;
33 while (flag1 >= 3);
34 flag2 = 3;
35 if (flag1 == 1) {
36 flag2 = 2;
37 while (flag1 != 4);
38 }
39 flag2 = 4;
40 while (flag1 >= 2);
41 // begin critical section
42 x = 1;
43 assert(x>=1);
44 // end critical section
45 while (2 <= flag1 && flag1 <= 3);
46 flag2 = 0;
47 return NULL;
48}
49
50int main(void) {
51 pthread_t t1, t2;
52 pthread_create(&t1, 0, thr1, 0);
53 pthread_create(&t2, 0, thr2, 0);
54 pthread_join(t1, 0);
55 pthread_join(t2, 0);
56 return 0;
57}
Note: See TracBrowser for help on using the repository browser.