1.23
2.0
main
test-branch
| Line | |
|---|
| 1 | /* Testcase from Threader's distribution. For details see:
|
|---|
| 2 | http://www.model.in.tum.de/~popeea/research/threader
|
|---|
| 3 |
|
|---|
| 4 | This file is adapted from the example introduced in the paper:
|
|---|
| 5 | Thread-Modular Verification for Shared-Memory Programs
|
|---|
| 6 | by Cormac Flanagan, Stephen Freund, Shaz Qadeer.
|
|---|
| 7 | */
|
|---|
| 8 |
|
|---|
| 9 | #include <pthread.h>
|
|---|
| 10 | #define assert(e) if (!(e)) ERROR: goto ERROR;
|
|---|
| 11 |
|
|---|
| 12 | int w=0, r=0, x=0, y=0;
|
|---|
| 13 |
|
|---|
| 14 | void __VERIFIER_atomic_take_write_lock() {
|
|---|
| 15 | __VERIFIER_assume(w==0 && r==0);
|
|---|
| 16 | w = 1;
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | void __VERIFIER_atomic_take_read_lock() {
|
|---|
| 20 | __VERIFIER_assume(w==0);
|
|---|
| 21 | r = r+1;
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | void *writer(void * arg) { //writer
|
|---|
| 25 | __VERIFIER_atomic_take_write_lock();
|
|---|
| 26 | x = 3;
|
|---|
| 27 | w = 0;
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | void *reader(void * arg) { //reader
|
|---|
| 31 | int l;
|
|---|
| 32 | __VERIFIER_atomic_take_read_lock();
|
|---|
| 33 | l = x;
|
|---|
| 34 | y = l;
|
|---|
| 35 | assert(y == x);
|
|---|
| 36 | l = r-1;
|
|---|
| 37 | r = l;
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | int main() {
|
|---|
| 41 | pthread_t t1, t2, t3, t4;
|
|---|
| 42 | pthread_create(&t1, 0, writer, 0);
|
|---|
| 43 | pthread_create(&t2, 0, reader, 0);
|
|---|
| 44 | pthread_create(&t3, 0, writer, 0);
|
|---|
| 45 | pthread_create(&t4, 0, reader, 0);
|
|---|
| 46 | pthread_join(t1, 0);
|
|---|
| 47 | pthread_join(t2, 0);
|
|---|
| 48 | pthread_join(t3, 0);
|
|---|
| 49 | pthread_join(t4, 0);
|
|---|
| 50 | return 0;
|
|---|
| 51 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.