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