source: CIVL/examples/pthread/threader/peterson_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: 939 bytes
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 turn = 1;
17 while (flag2==1 && turn==1) {};
18 // begin: critical section
19 x = 0;
20 assert(x<=0);
21 // end: critical section
22 flag1 = 0;
23}
24
25void *thr2() {
26 flag2 = 1;
27 turn = 0;
28 while (flag1==1 && turn==0) {};
29 // begin: critical section
30 x = 1;
31 assert(x>=1);
32 // end: critical section
33 flag2 = 0;
34}
35
36int main() {
37 pthread_t t1, t2;
38 pthread_create(&t1, 0, thr1, 0);
39 pthread_create(&t2, 0, thr2, 0);
40 pthread_join(t1, 0);
41 pthread_join(t2, 0);
42 return 0;
43}
Note: See TracBrowser for help on using the repository browser.