source: CIVL/examples/pthread/threader/dekker_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.1 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 flag1 = 0, flag2 = 0; // boolean flags
11int turn; // integer variable to hold the ID of the thread whose turn is it
12int x; // boolean variable to test mutual exclusion
13
14void *thr1() {
15 flag1 = 1;
16 while (flag2 >= 1) {
17 if (turn != 0) {
18 flag1 = 0;
19 while (turn != 0) {};
20 flag1 = 1;
21 }
22 }
23 // begin: critical section
24 x = 0;
25 assert(x<=0);
26 // end: critical section
27 turn = 1;
28 flag1 = 0;
29}
30
31void *thr2() {
32 flag2 = 1;
33 while (flag1 >= 1) {
34 if (turn != 1) {
35 flag2 = 0;
36 while (turn != 1) {};
37 flag2 = 1;
38 }
39 }
40 // begin: critical section
41 x = 1;
42 assert(x>=1);
43 // end: critical section
44 turn = 1;
45 flag2 = 0;
46}
47
48int main() {
49 pthread_t t1, t2;
50 __VERIFIER_assume(0<=turn && turn<=1);
51 pthread_create(&t1, 0, thr1, 0);
52 pthread_create(&t2, 0, thr2, 0);
53 pthread_join(t1, 0);
54 pthread_join(t2, 0);
55 return 0;
56}
Note: See TracBrowser for help on using the repository browser.