source: CIVL/examples/pthread/cprover/10_fmaxsym_cas_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: 1017 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
6#define WORKPERTHREAD 2
7#define THREADSMAX 3
8volatile int max = 0x80000000;
9
10int storage[WORKPERTHREAD*THREADSMAX];
11
12void __VERIFIER_atomic_CAS(
13 volatile int *v,
14 int e,
15 int u,
16 int *r)
17{
18 if(*v == e)
19 {
20 *v = u, *r = 1;
21 }
22 else
23 {
24 *r = 0;
25 }
26}
27
28inline void findMax(int offset){
29 int i;
30 int e;
31 int c;
32 int cret;
33
34 for(i = offset; i < offset+WORKPERTHREAD; i++) {
35 e = storage[i];
36
37 while(1){
38 c = max;
39 if(e > c){
40 __VERIFIER_atomic_CAS(&max,c,e,&cret);
41 if(cret){
42 break;
43 }
44 }else{
45 break;
46 }
47 }
48
49 assert(e <= max);
50 }
51}
52
53void* thr1(void* arg) {
54 int offset;
55
56 assume(offset % WORKPERTHREAD == 0 && offset >= 0 && offset < WORKPERTHREAD*THREADSMAX);
57 //assume(offset < WORKPERTHREAD && offset >= 0 && offset < WORKPERTHREAD*THREADSMAX);
58
59 findMax(offset);
60
61 return 0;
62}
63
64int main(){
65 pthread_t t;
66
67 while(1) { pthread_create(&t, 0, thr1, 0); }
68}
69
Note: See TracBrowser for help on using the repository browser.