source: CIVL/examples/pthread/threader/dekker_true.c@ 83af34d

1.23 2.0 main test-branch
Last change on this file since 83af34d 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
RevLine 
[9e44c01]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; // boolean flags
[dc245be]9int turn; // integer variable to hold the ID of the thread whose turn is it
[9e44c01]10int x; // boolean variable to test mutual exclusion
11
[dc245be]12void *thr1() {
[9e44c01]13 flag1 = 1;
14 while (flag2 >= 1) {
15 if (turn != 0) {
16 flag1 = 0;
17 while (turn != 0) {};
18 flag1 = 1;
19 }
20 }
21 // begin: critical section
22 x = 0;
23 assert(x<=0);
24 // end: critical section
25 turn = 1;
26 flag1 = 0;
27}
28
[dc245be]29void *thr2() {
[9e44c01]30 flag2 = 1;
31 while (flag1 >= 1) {
32 if (turn != 1) {
33 flag2 = 0;
34 while (turn != 1) {};
35 flag2 = 1;
36 }
37 }
38 // begin: critical section
39 x = 1;
40 assert(x>=1);
41 // end: critical section
42 turn = 1;
43 flag2 = 0;
44}
45
46int main() {
47 pthread_t t1, t2;
48 __VERIFIER_assume(0<=turn && turn<=1);
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.