source: CIVL/examples/pthread/threader/read_write_lock_true-unreach-call.c@ 7d77e64

main test-branch
Last change on this file since 7d77e64 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.2 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 __VERIFIER_atomic_release_read_lock() {
27 r = r-1;
28}
29
30void *writer() { //writer
31 __VERIFIER_atomic_take_write_lock();
32 x = 3;
33 w = 0;
34}
35
36void *reader() { //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}
44
45int main() {
46 pthread_t t1, t2, t3, t4;
47 pthread_create(&t1, 0, writer, 0);
48 pthread_create(&t2, 0, reader, 0);
49 pthread_create(&t3, 0, writer, 0);
50 pthread_create(&t4, 0, reader, 0);
51 pthread_join(t1, 0);
52 pthread_join(t2, 0);
53 pthread_join(t3, 0);
54 pthread_join(t4, 0);
55 return 0;
56}
Note: See TracBrowser for help on using the repository browser.