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:
757 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 a = 1;
|
|---|
| 7 | int b = 2;
|
|---|
| 8 | int c = 3;
|
|---|
| 9 | int temp;
|
|---|
| 10 |
|
|---|
| 11 | int mutex;
|
|---|
| 12 |
|
|---|
| 13 | void __VERIFIER_atomic_acquire()
|
|---|
| 14 | {
|
|---|
| 15 | assume(mutex==0);
|
|---|
| 16 | mutex = 1;
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | void __VERIFIER_atomic_release()
|
|---|
| 20 | {
|
|---|
| 21 | assume(mutex==1);
|
|---|
| 22 | mutex = 0;
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 | void* thr2(void* arg)
|
|---|
| 27 | {
|
|---|
| 28 | for(;;){
|
|---|
| 29 | __VERIFIER_atomic_acquire();
|
|---|
| 30 | temp = a;
|
|---|
| 31 | a = b;
|
|---|
| 32 | b = c;
|
|---|
| 33 | c = temp;
|
|---|
| 34 | __VERIFIER_atomic_release();
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | return 0;
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | void* thr1(void* arg)
|
|---|
| 41 | {
|
|---|
| 42 | while(1)
|
|---|
| 43 | {
|
|---|
| 44 | __VERIFIER_atomic_acquire();
|
|---|
| 45 | assert(a != b);
|
|---|
| 46 | __VERIFIER_atomic_release();
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | return 0;
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | int main() {
|
|---|
| 53 | pthread_t t;
|
|---|
| 54 |
|
|---|
| 55 | pthread_create(&t, 0, thr1, 0);
|
|---|
| 56 | while(1)
|
|---|
| 57 | {
|
|---|
| 58 | pthread_create(&t, 0, thr2, 0);
|
|---|
| 59 | }
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.