1.23
2.0
main
test-branch
|
Last change
on this file since d87ec9c was 8d512ae, checked in by John Edenhofner <johneden@…>, 12 years ago |
|
Changed location of pthread.cvh, and updated files to use pthread.h (which includes pthread.cvh). New translations from pthread-atomic, and updated pthread.cvh
git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@1092 fb995dde-84ed-4084-dfe6-e5aef3e2452c
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| 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 | #include <civlc.h>
|
|---|
| 11 | #define assert(e) if (!(e)) $assert($false);
|
|---|
| 12 |
|
|---|
| 13 | int w=0, r=0, x=0, y;
|
|---|
| 14 |
|
|---|
| 15 | void __VERIFIER_atomic_take_write_lock() {
|
|---|
| 16 | $when(w==0 && r==0);
|
|---|
| 17 | w = 1;
|
|---|
| 18 | }
|
|---|
| 19 |
|
|---|
| 20 | void __VERIFIER_atomic_take_read_lock() {
|
|---|
| 21 | $when(w==0);
|
|---|
| 22 | r = r+1;
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | void *writer(void *arg) { //writer
|
|---|
| 26 | __VERIFIER_atomic_take_write_lock();
|
|---|
| 27 | x = 3;
|
|---|
| 28 | w = 0;
|
|---|
| 29 | return NULL;
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | void *reader(void *arg) { //reader
|
|---|
| 33 | int l;
|
|---|
| 34 | __VERIFIER_atomic_take_read_lock();
|
|---|
| 35 | l = x;
|
|---|
| 36 | y = l;
|
|---|
| 37 | assert(y == x);
|
|---|
| 38 | l = r-1;
|
|---|
| 39 | r = l;
|
|---|
| 40 | return NULL;
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | int main(void) {
|
|---|
| 44 | pthread_t t1, t2, t3, t4;
|
|---|
| 45 | pthread_create(&t1, 0, writer, 0);
|
|---|
| 46 | pthread_create(&t2, 0, reader, 0);
|
|---|
| 47 | pthread_create(&t3, 0, writer, 0);
|
|---|
| 48 | pthread_create(&t4, 0, reader, 0);
|
|---|
| 49 | pthread_join(t1, 0);
|
|---|
| 50 | pthread_join(t2, 0);
|
|---|
| 51 | pthread_join(t3, 0);
|
|---|
| 52 | pthread_join(t4, 0);
|
|---|
| 53 | return 0;
|
|---|
| 54 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.