source: CIVL/examples/pthread/threader/read_write_lock_false.c@ e0fc189

1.23 2.0 main test-branch
Last change on this file since e0fc189 was e3151da, checked in by Ziqing Luo <ziqing@…>, 11 years ago

re-organized example directory

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@1763 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#define assert(e) if (!(e)) ERROR: goto ERROR;
11
12int w=0, r=0, x=0, y=0;
13
14void __VERIFIER_atomic_take_write_lock() {
15 __VERIFIER_assume(w==0 && r==0);
16 w = 1;
17}
18
19void __VERIFIER_atomic_take_read_lock() {
20 __VERIFIER_assume(w==0);
21 r = r+1;
22}
23
24void *writer(void * arg) { //writer
25 __VERIFIER_atomic_take_write_lock();
26 x = 3;
27 w = 0;
28}
29
30void *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
40int 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.