source: CIVL/examples/pthread/cprover/01_inc_true.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: 706 bytes
Line 
1//http://www.ibm.com/developerworks/java/library/j-jtp04186/index.html
2//A counter using locks
3
4#include <pthread.h>
5
6#define assume(e) __VERIFIER_assume(e)
7#define assert(e) { if(!(e)) { ERROR: goto ERROR; (void)0; } }
8
9volatile unsigned value, m = 0;
10
11void __VERIFIER_atomic_acquire()
12{
13 assume(m==0);
14 m = 1;
15}
16
17void __VERIFIER_atomic_release()
18{
19 assume(m==1);
20 m = 0;
21}
22
23void * thr1(void* arg) {
24 unsigned v = 0;
25 __VERIFIER_atomic_acquire();
26 if(value == 0u-1) {
27 __VERIFIER_atomic_release();
28
29 return 0;
30 }else{
31
32 v = value;
33 value = v + 1;
34 __VERIFIER_atomic_release();
35 assert(value > v);
36
37 return 0;
38 }
39}
40
41int main(){
42 pthread_t t;
43
44 while(1) {
45 pthread_create(&t, 0, thr1, 0);
46 }
47}
48
Note: See TracBrowser for help on using the repository browser.