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:
1004 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 | void __VERIFIER_atomic_acquire(int * m)
|
|---|
| 7 | {
|
|---|
| 8 | assume(*m==0);
|
|---|
| 9 | *m = 1;
|
|---|
| 10 | }
|
|---|
| 11 |
|
|---|
| 12 | void __VERIFIER_atomic_release(int * m)
|
|---|
| 13 | {
|
|---|
| 14 | assume(*m==1);
|
|---|
| 15 | *m = 0;
|
|---|
| 16 | }
|
|---|
| 17 |
|
|---|
| 18 | int block;
|
|---|
| 19 | int busy; // boolean flag indicating whether the block has be an allocated to an inode
|
|---|
| 20 | int inode;
|
|---|
| 21 | int m_inode=0; // protects the inode
|
|---|
| 22 | int m_busy=0; // protects the busy flag
|
|---|
| 23 |
|
|---|
| 24 | void * thr1(void* arg)
|
|---|
| 25 | {
|
|---|
| 26 | __VERIFIER_atomic_acquire(&m_inode);
|
|---|
| 27 | if(inode == 0){
|
|---|
| 28 | __VERIFIER_atomic_acquire(&m_busy);
|
|---|
| 29 | busy = 1;
|
|---|
| 30 | __VERIFIER_atomic_release(&m_busy);
|
|---|
| 31 | inode = 1;
|
|---|
| 32 | }
|
|---|
| 33 | block = 1;
|
|---|
| 34 | assert(block == 1);
|
|---|
| 35 | __VERIFIER_atomic_release(&m_inode);
|
|---|
| 36 |
|
|---|
| 37 | return 0;
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | void * thr2(void* arg)
|
|---|
| 41 | {
|
|---|
| 42 | __VERIFIER_atomic_acquire(&m_busy);
|
|---|
| 43 | if(busy == 0){
|
|---|
| 44 | block = 0;
|
|---|
| 45 | assert(block == 0);
|
|---|
| 46 | }
|
|---|
| 47 | __VERIFIER_atomic_release(&m_busy);
|
|---|
| 48 |
|
|---|
| 49 | return 0;
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | int main()
|
|---|
| 53 | {
|
|---|
| 54 | pthread_t t;
|
|---|
| 55 |
|
|---|
| 56 | pthread_create(&t, 0, thr1, 0);
|
|---|
| 57 | thr2(0);
|
|---|
| 58 |
|
|---|
| 59 | return 0;
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.