source: CIVL/examples/pthread/threader/time_var_mutex_true-unreach-call.c@ 1aaefd4

main test-branch
Last change on this file since 1aaefd4 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.4 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 block;
15int busy; // boolean flag indicating whether the block has been allocated to an inode
16int inode;
17pthread_mutex_t m_inode; // protects the inode
18pthread_mutex_t m_busy; // protects the busy flag
19
20void *allocator(){
21 pthread_mutex_lock(&m_inode);
22 if(inode == 0){
23 pthread_mutex_lock(&m_busy);
24 busy = 1;
25 pthread_mutex_unlock(&m_busy);
26 inode = 1;
27 }
28 block = 1;
29 assert(block == 1);
30 pthread_mutex_unlock(&m_inode);
31 return NULL;
32}
33
34void *de_allocator(){
35 pthread_mutex_lock(&m_busy);
36 if(busy == 0){
37 block = 0;
38 assert(block == 0);
39 }
40 pthread_mutex_unlock(&m_busy);
41 return ((void *)0);
42}
43
44int main() {
45 pthread_t t1, t2;
46 __VERIFIER_assume(inode == busy);
47 pthread_mutex_init(&m_inode, 0);
48 pthread_mutex_init(&m_busy, 0);
49 pthread_create(&t1, 0, allocator, 0);
50 pthread_create(&t2, 0, de_allocator, 0);
51 pthread_join(t1, 0);
52 pthread_join(t2, 0);
53 pthread_mutex_destroy(&m_inode);
54 pthread_mutex_destroy(&m_busy);
55 return 0;
56}
Note: See TracBrowser for help on using the repository browser.