source: CIVL/examples/pthread/esbmc/stateful01_true.c@ 4a5679a

1.23 2.0 main test-branch
Last change on this file since 4a5679a 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: 746 bytes
Line 
1#include <pthread.h>
2
3pthread_mutex_t ma, mb;
4int data1, data2;
5
6void * thread1(void * arg)
7{
8 pthread_mutex_lock(&ma);
9 data1++;
10 pthread_mutex_unlock(&ma);
11
12 pthread_mutex_lock(&ma);
13 data2++;
14 pthread_mutex_unlock(&ma);
15}
16
17
18void * thread2(void * arg)
19{
20 pthread_mutex_lock(&ma);
21 data1+=5;
22 pthread_mutex_unlock(&ma);
23
24 pthread_mutex_lock(&ma);
25 data2-=6;
26 pthread_mutex_unlock(&ma);
27}
28
29int main()
30{
31 pthread_t t1, t2;
32
33 pthread_mutex_init(&ma, 0);
34 pthread_mutex_init(&mb, 0);
35
36 data1 = 10;
37 data2 = 10;
38
39 pthread_create(&t1, 0, thread1, 0);
40 pthread_create(&t2, 0, thread2, 0);
41
42 pthread_join(t1, 0);
43 pthread_join(t2, 0);
44
45 if (data1!=16 && data2!=5)
46 {
47 ERROR: goto ERROR;
48 ;
49 }
50
51 return 0;
52}
53
Note: See TracBrowser for help on using the repository browser.