source: CIVL/examples/pthread/threader/read_write_lock_false-unreach-call.c@ bb03188

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