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

1.23 2.0 acw/focus-triggers 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_true.cvl
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
23
24void *thread2(void*arg)
25{
26 pthread_mutex_lock(&ma);
27 data1+=5;
28 pthread_mutex_unlock(&ma);
29
30 pthread_mutex_lock(&ma);
31 data2-=6;
32 pthread_mutex_unlock(&ma);
33}
34
35
36void main()
37{
38 pthread_t t1, t2;
39
40 pthread_mutex_init(&ma, 0);
41 pthread_mutex_init(&mb, 0);
42
43 data1 = 10;
44 data2 = 10;
45
46 pthread_create(&t1, 0, thread1, 0);
47 pthread_create(&t2, 0, thread2, 0);
48
49 pthread_join(t1, 0);
50 pthread_join(t2, 0);
51
52 if (data1!=16 && data2!=5)
53 {
54 $assert($false);
55 }
56}
Note: See TracBrowser for help on using the repository browser.