source: CIVL/examples/pthread/threader/szymanski_true.c@ 5c27aa5

1.23 2.0 main test-branch
Last change on this file since 5c27aa5 was e3151da, checked in by Ziqing Luo <ziqing@…>, 11 years ago

re-organized example directory

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@1763 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 1.0 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#define assert(e) if (!(e)) ERROR: goto ERROR;
7
8int flag1 = 0, flag2 = 0; // integer flags
9int x; // boolean variable to test mutual exclusion
10
11void *thr1(void * arg) {
12 flag1 = 1;
13 while (flag2 >= 3);
14 flag1 = 3;
15 if (flag2 == 1) {
16 flag1 = 2;
17 while (flag2 != 4);
18 }
19 flag1 = 4;
20 while (flag2 >= 2);
21 // begin critical section
22 x = 0;
23 assert(x<=0);
24 // end critical section
25 while (2 <= flag2 && flag2 <= 3);
26 flag1 = 0;
27}
28
29void *thr2(void * arg) {
30 flag2 = 1;
31 while (flag1 >= 3);
32 flag2 = 3;
33 if (flag1 == 1) {
34 flag2 = 2;
35 while (flag1 != 4);
36 }
37 flag2 = 4;
38 while (flag1 >= 2);
39 // begin critical section
40 x = 1;
41 assert(x>=1);
42 // end critical section
43 while (2 <= flag1 && flag1 <= 3);
44 flag2 = 0;
45}
46
47int main() {
48 pthread_t t1, t2;
49 pthread_create(&t1, 0, thr1, 0);
50 pthread_create(&t2, 0, thr2, 0);
51 pthread_join(t1, 0);
52 pthread_join(t2, 0);
53 return 0;
54}
Note: See TracBrowser for help on using the repository browser.