source: CIVL/examples/pthread/cprover/17_szymanski_true.c@ 1aaefd4

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: 992 bytes
Line 
1#include <pthread.h>
2
3#define assert(e) { if(!(e)) { ERROR: goto ERROR; (void)0; } }
4
5int flag1 = 0, flag2 = 0; // N integer flags
6int x; // variable to test mutual exclusion
7
8void* thr1(void* arg) {
9 while (1) {
10 flag1 = 1;
11 while (flag2 >= 3);
12 flag1 = 3;
13 if (flag2 == 1) {
14 flag1 = 2;
15 while (flag2 != 4);
16 }
17 flag1 = 4;
18 while (flag2 >= 2);
19 // begin critical section
20 x = 0;
21 assert(x<=0);
22 // end critical section
23 while (2 <= flag2 && flag2 <= 3);
24 flag1 = 0;
25 }
26
27 return 0;
28}
29
30void* thr2(void* arg) {
31 while (1) {
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 }
48
49 return 0;
50}
51
52int main()
53{
54 pthread_t t;
55
56 pthread_create(&t, 0, thr1, 0);
57 thr2(0);
58
59 return 0;
60}
61
Note: See TracBrowser for help on using the repository browser.