source: CIVL/examples/pthread/cprover/40_barrier_vf_false.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: 1.1 KB
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
6volatile unsigned int count = 0; //shared
7_Bool MTX = 0; //shared mutex
8__thread _Bool COND = 0; //condition variables become local flag indicating whether the thread was signaled
9
10void __VERIFIER_atomic_acquire()
11{
12 assume(MTX==0);
13 MTX = 1;
14}
15
16void __VERIFIER_atomic_release()
17{
18 assume(MTX==1);
19 MTX = 0;
20}
21
22#define cnd_wait(c,m){ \
23 __VERIFIER_atomic_release(); \
24 assume(c); \
25 c = 0; \
26 __VERIFIER_atomic_acquire(); }
27
28#define cnd_broadcast(c) (c = 1) //BP must be post-processed manually by changing "b*_COND := 1" to "b*_COND$ := 1"
29
30void Barrier2() {
31 __VERIFIER_atomic_acquire();
32 count++;
33 if (count == 3) {
34 cnd_broadcast(COND); //pthread_cond_broadcast(&cond);
35 count = 0; }
36 else
37 cnd_wait(COND,MTX); //pthread_cond_wait(&cond, &m);
38 __VERIFIER_atomic_release(); }
39
40void* thr1(void* arg){
41 Barrier2();
42 assert(0);
43
44 return 0;
45} //should not fail for <3 threads
46
47int main(){
48 pthread_t t;
49
50 while(1) { pthread_create(&t, 0, thr1, 0); }
51}
Note: See TracBrowser for help on using the repository browser.