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

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since be4355b was 5fb1a47, checked in by Manchun Zheng <zmanchun@…>, 12 years ago

added pthread examples

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

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