source: CIVL/examples/pthread/threader/lamport_true-unreach-call.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: 1.3 KB
Line 
1extern void __VERIFIER_error() __attribute__ ((__noreturn__));
2
3/* Testcase from Threader's distribution. For details see:
4 http://www.model.in.tum.de/~popeea/research/threader
5*/
6
7#include <pthread.h>
8#define assert(e) if (!(e)) ERROR: __VERIFIER_error();
9
10int x, y;
11int b1, b2; // boolean flags
12int X; // boolean variable to test mutual exclusion
13
14void *thr1() {
15 while (1) {
16 b1 = 1;
17 x = 1;
18 if (y != 0) {
19 b1 = 0;
20 while (y != 0) {};
21 continue;
22 }
23 y = 1;
24 if (x != 1) {
25 b1 = 0;
26 while (b2 >= 1) {};
27 if (y != 1) {
28 while (y != 0) {};
29 continue;
30 }
31 }
32 break;
33 }
34 // begin: critical section
35 X = 0;
36 assert(X <= 0);
37 // end: critical section
38 y = 0;
39 b1 = 0;
40}
41
42void *thr2() {
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}
69
70int main() {
71 pthread_t t1, t2;
72 pthread_create(&t1, 0, thr1, 0);
73 pthread_create(&t2, 0, thr2, 0);
74 pthread_join(t1, 0);
75 pthread_join(t2, 0);
76 return 0;
77}
Note: See TracBrowser for help on using the repository browser.