source: CIVL/examples/pthread/cprover/31_simple_loop5_vs_true.c@ bb03188

main test-branch
Last change on this file since bb03188 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: 757 bytes
Line 
1#include <pthread.h>
2
3#define assume(e) __VERIFIER_assume(e)
4#define assert(e) { if(!(e)) { ERROR: goto ERROR; (void)0; } }
5
6int a = 1;
7int b = 2;
8int c = 3;
9int temp;
10
11int mutex;
12
13void __VERIFIER_atomic_acquire()
14{
15 assume(mutex==0);
16 mutex = 1;
17}
18
19void __VERIFIER_atomic_release()
20{
21 assume(mutex==1);
22 mutex = 0;
23}
24
25
26void* thr2(void* arg)
27{
28 for(;;){
29 __VERIFIER_atomic_acquire();
30 temp = a;
31 a = b;
32 b = c;
33 c = temp;
34 __VERIFIER_atomic_release();
35 }
36
37 return 0;
38}
39
40void* thr1(void* arg)
41{
42 while(1)
43 {
44 __VERIFIER_atomic_acquire();
45 assert(a != b);
46 __VERIFIER_atomic_release();
47 }
48
49 return 0;
50}
51
52int main() {
53 pthread_t t;
54
55 pthread_create(&t, 0, thr1, 0);
56 while(1)
57 {
58 pthread_create(&t, 0, thr2, 0);
59 }
60}
61
Note: See TracBrowser for help on using the repository browser.