source: CIVL/examples/pthread/cprover/30_Function_Pointer3_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: 823 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 mutex;
7int res;
8
9void __VERIFIER_atomic_acquire()
10{
11 assume(mutex==0);
12 mutex = 1;
13}
14
15void __VERIFIER_atomic_release()
16{
17 assume(mutex==1);
18 mutex = 0;
19}
20
21typedef int (*FuncType)(int, int);
22
23inline int f1(int a, int b)
24{
25 return a+b+1;
26}
27
28inline int f2(int x, int y)
29{
30 return x-y+2;
31}
32
33void* thr2(void* arg)
34{
35 FuncType pf;
36
37 if( __VERIFIER_nondet_int() )
38 pf = f1;
39 else
40 pf = f2;
41
42 __VERIFIER_atomic_acquire();
43 res = pf(4,3);
44 __VERIFIER_atomic_release();
45
46 return 0;
47}
48
49void* thr1(void* arg)
50{
51 while(1)
52 {
53 assert(res < 10);
54 }
55
56 return 0;
57}
58
59
60int main()
61{
62 pthread_t t;
63
64 pthread_create(&t, 0, thr1, 0);
65 while(1)
66 {
67 pthread_create(&t, 0, thr2, 0);
68 }
69}
70
71
Note: See TracBrowser for help on using the repository browser.