source: CIVL/examples/translation/pthread/read_write_lock_true.cvl@ d87ec9c

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.2 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
13int w=0, r=0, x=0, y;
14
15void __VERIFIER_atomic_take_write_lock() {
16 $when(w==0 && r==0);
17 w = 1;
18}
19
20void __VERIFIER_atomic_take_read_lock() {
21 $when(w==0);
22 r = r+1;
23}
24
25void __VERIFIER_atomic_release_read_lock() {
26 r = r-1;
27}
28
29void *writer(void *arg) { //writer
30 __VERIFIER_atomic_take_write_lock();
31 x = 3;
32 w = 0;
33 return NULL;
34}
35
36void *reader(void *arg) { //reader
37 int l;
38 __VERIFIER_atomic_take_read_lock();
39 l = x;
40 y = l;
41 assert(y == x);
42 __VERIFIER_atomic_release_read_lock();
43 return NULL;
44}
45
46int main(void) {
47 pthread_t t1, t2, t3, t4;
48 pthread_create(&t1, 0, writer, 0);
49 pthread_create(&t2, 0, reader, 0);
50 pthread_create(&t3, 0, writer, 0);
51 pthread_create(&t4, 0, reader, 0);
52 pthread_join(t1, 0);
53 pthread_join(t2, 0);
54 pthread_join(t3, 0);
55 pthread_join(t4, 0);
56 return 0;
57}
Note: See TracBrowser for help on using the repository browser.