source: CIVL/examples/translation/pthread/stateful01_false.cvl@ bfebb46

1.23 2.0 main test-branch
Last change on this file since bfebb46 was a83ea55, checked in by Manchun Zheng <zmanchun@…>, 12 years ago

added comments to pthread examples.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@822 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100755
File size: 806 bytes
Line 
1/**
2* Command line execution:
3* civl verify stateful01_false.cvl -min
4*/
5
6#include <civlc.h>
7#include "pthread.cvh"
8
9pthread_mutex_t ma, mb;
10int data1, data2;
11
12void *thread1(void*arg)
13{
14 pthread_mutex_lock(&ma);
15 data1++;
16 pthread_mutex_unlock(&ma);
17
18 pthread_mutex_lock(&ma);
19 data2++;
20 pthread_mutex_unlock(&ma);
21}
22
23void *thread2(void*arg)
24{
25 pthread_mutex_lock(&ma);
26 data1+=5;
27 pthread_mutex_unlock(&ma);
28
29 pthread_mutex_lock(&ma);
30 data2-=6;
31 pthread_mutex_unlock(&ma);
32}
33
34void main()
35{
36 pthread_t t1, t2;
37
38 pthread_mutex_init(&ma, 0);
39 pthread_mutex_init(&mb, 0);
40
41 data1 = 10;
42 data2 = 10;
43
44 pthread_create(&t1, 0, thread1, 0);
45 pthread_create(&t2, 0, thread2, 0);
46
47 pthread_join(t1, 0);
48 pthread_join(t2, 0);
49
50 if (data1==16 && data2==5)
51 {
52 $assert($false);
53 }
54}
Note: See TracBrowser for help on using the repository browser.