source: CIVL/examples/translation/pthread/lamport_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.3 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 x, y=0;
10int b1, b2; // boolean flags
11int X; // boolean variable to test mutual exclusion
12
13void *thr1(void *arg) {
14 while (1) {
15 b1 = 1;
16 x = 1;
17 if (y != 0) {
18 b1 = 0;
19 while (y != 0) {};
20 continue;
21 }
22 y = 1;
23 if (x != 1) {
24 b1 = 0;
25 while (b2 >= 1) {};
26 if (y != 1) {
27 while (y != 0) {};
28 continue;
29 }
30 }
31 break;
32 }
33 // begin: critical section
34 X = 0;
35 assert(X <= 0);
36 // end: critical section
37 y = 0;
38 b1 = 0;
39 return NULL;
40}
41
42void *thr2(void *arg) {
43 while (1) {
44 b2 = 1;
45 x = 2;
46 if (y != 0) {
47 b2 = 0;
48 while (y != 0) {};
49 continue;
50 }
51 y = 2;
52 if (x != 2) {
53 b2 = 0;
54 while (b1 >= 1) {};
55 if (y != 2) {
56 while (y != 0) {};
57 continue;
58 }
59 }
60 break;
61 }
62 // begin: critical section
63 X = 1;
64 assert(X >= 1);
65 // end: critical section
66 y = 0;
67 b2 = 0;
68 return NULL;
69}
70
71int main(void) {
72 pthread_t t1, t2;
73 pthread_create(&t1, 0, thr1, 0);
74 pthread_create(&t2, 0, thr2, 0);
75 pthread_join(t1, 0);
76 pthread_join(t2, 0);
77 return 0;
78}
Note: See TracBrowser for help on using the repository browser.