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:
951 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 | #define WORKPERTHREAD 2
|
|---|
| 7 | #define THREADSMAX 3
|
|---|
| 8 | volatile int max = 0x80000000, m = 0;
|
|---|
| 9 |
|
|---|
| 10 | void __VERIFIER_atomic_acquire()
|
|---|
| 11 | {
|
|---|
| 12 | assume(m==0);
|
|---|
| 13 | m = 1;
|
|---|
| 14 | }
|
|---|
| 15 |
|
|---|
| 16 | void __VERIFIER_atomic_release()
|
|---|
| 17 | {
|
|---|
| 18 | assume(m==1);
|
|---|
| 19 | m = 0;
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | int storage[WORKPERTHREAD*THREADSMAX];
|
|---|
| 23 |
|
|---|
| 24 | inline void findMax(int offset)
|
|---|
| 25 | {
|
|---|
| 26 | int i;
|
|---|
| 27 | int e;
|
|---|
| 28 |
|
|---|
| 29 | for(i = offset; i < offset+WORKPERTHREAD; i++) {
|
|---|
| 30 | e = storage[i];
|
|---|
| 31 |
|
|---|
| 32 | __VERIFIER_atomic_acquire();
|
|---|
| 33 | {
|
|---|
| 34 | if(e > max) {
|
|---|
| 35 | max = e;
|
|---|
| 36 | }
|
|---|
| 37 | }
|
|---|
| 38 | __VERIFIER_atomic_release();
|
|---|
| 39 | assert(e <= max);
|
|---|
| 40 | }
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | void* thr1(void* arg) {
|
|---|
| 44 | int offset;
|
|---|
| 45 |
|
|---|
| 46 | assume(offset % WORKPERTHREAD == 0 && offset >= 0 && offset < WORKPERTHREAD*THREADSMAX);
|
|---|
| 47 | //assume(offset < WORKPERTHREAD && offset >= 0 && offset < WORKPERTHREAD*THREADSMAX);
|
|---|
| 48 |
|
|---|
| 49 | findMax(offset);
|
|---|
| 50 |
|
|---|
| 51 | return 0;
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | int main(){
|
|---|
| 55 | pthread_t t;
|
|---|
| 56 |
|
|---|
| 57 | while(1) { pthread_create(&t, 0, thr1, 0); }
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.