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:
582 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 | int w=0, r=0, x, y;
|
|---|
| 7 |
|
|---|
| 8 | void __VERIFIER_atomic_w()
|
|---|
| 9 | {
|
|---|
| 10 | assume(w==0);
|
|---|
| 11 | assume(r==0);
|
|---|
| 12 | w = 1;
|
|---|
| 13 | }
|
|---|
| 14 |
|
|---|
| 15 | void* thr1(void* arg) { //writer
|
|---|
| 16 | __VERIFIER_atomic_w();
|
|---|
| 17 | x = 3;
|
|---|
| 18 | w = 0;
|
|---|
| 19 |
|
|---|
| 20 | return 0;
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | void __VERIFIER_atomic_r()
|
|---|
| 24 | {
|
|---|
| 25 | assume(w==0);
|
|---|
| 26 | r = r+1;
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | void* thr2(void* arg) { //reader
|
|---|
| 30 | __VERIFIER_atomic_r();
|
|---|
| 31 | y = x;
|
|---|
| 32 | assert(y == x);
|
|---|
| 33 | r = r-1;
|
|---|
| 34 |
|
|---|
| 35 | return 0;
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | int main()
|
|---|
| 39 | {
|
|---|
| 40 | pthread_t t;
|
|---|
| 41 |
|
|---|
| 42 | pthread_create(&t, 0, thr1, 0);
|
|---|
| 43 | thr2(0);
|
|---|
| 44 |
|
|---|
| 45 | return 0;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.