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:
1.1 KB
|
| Line | |
|---|
| 1 | #include <pthread.h>
|
|---|
| 2 |
|
|---|
| 3 | #define assume(e) __VERIFIER_assume(e)
|
|---|
| 4 | #define assert_nl(e) { if(!(e)) { goto ERROR; } }
|
|---|
| 5 | #define assert(e) { if(!(e)) { ERROR: goto ERROR; (void)0; } }
|
|---|
| 6 |
|
|---|
| 7 | #define WORKPERTHREAD 2
|
|---|
| 8 | #define THREADSMAX 3
|
|---|
| 9 | volatile int max = 0x80000000, m = 0;
|
|---|
| 10 |
|
|---|
| 11 | void __VERIFIER_atomic_acquire()
|
|---|
| 12 | {
|
|---|
| 13 | assume(m==0);
|
|---|
| 14 | m = 1;
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | void __VERIFIER_atomic_release()
|
|---|
| 18 | {
|
|---|
| 19 | assume(m==1);
|
|---|
| 20 | m = 0;
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | int storage[WORKPERTHREAD*THREADSMAX];
|
|---|
| 24 |
|
|---|
| 25 | inline void findMax(int offset){
|
|---|
| 26 |
|
|---|
| 27 | int i;
|
|---|
| 28 | int e;
|
|---|
| 29 | int my_max = 0x80000000;
|
|---|
| 30 |
|
|---|
| 31 | for(i = offset; i < offset+WORKPERTHREAD; i++) {
|
|---|
| 32 | #ifndef NOBUG
|
|---|
| 33 | e = storage[i];
|
|---|
| 34 | #else
|
|---|
| 35 | e = rand();
|
|---|
| 36 | #endif
|
|---|
| 37 |
|
|---|
| 38 | if(e > my_max) {
|
|---|
| 39 | my_max = e;
|
|---|
| 40 | }
|
|---|
| 41 | assert_nl(e <= my_max);
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | __VERIFIER_atomic_acquire();
|
|---|
| 45 | {
|
|---|
| 46 | if(my_max > max) {
|
|---|
| 47 | max = my_max;
|
|---|
| 48 | }
|
|---|
| 49 | }
|
|---|
| 50 | __VERIFIER_atomic_release();
|
|---|
| 51 |
|
|---|
| 52 | assert(my_max <= max);
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | void* thr1(void* arg) {
|
|---|
| 56 | int offset;
|
|---|
| 57 |
|
|---|
| 58 | assume(offset % WORKPERTHREAD == 0 && offset >= 0 && offset < WORKPERTHREAD*THREADSMAX);
|
|---|
| 59 | //assume(offset < WORKPERTHREAD && offset >= 0 && offset < WORKPERTHREAD*THREADSMAX);
|
|---|
| 60 |
|
|---|
| 61 | findMax(offset);
|
|---|
| 62 |
|
|---|
| 63 | return 0;
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | int main(){
|
|---|
| 67 | pthread_t t;
|
|---|
| 68 |
|
|---|
| 69 | while(1) { pthread_create(&t, 0, thr1, 0); }
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.