source: CIVL/examples/translation/pthread/stateful01_false.c@ 4540352

1.23 2.0 main test-branch
Last change on this file since 4540352 was e182ee04, checked in by John Edenhofner <johneden@…>, 12 years ago

Added basic scheduling header, modified pthread_mutex_lock as well as mutliple other methods

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

  • Property mode set to 100644
File size: 787 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 pthread_exit(NULL);
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 pthread_exit(NULL);
29}
30
31
32int main()
33{
34 pthread_t t1, t2;
35
36 pthread_mutex_init(&ma, 0);
37 pthread_mutex_init(&mb, 0);
38
39 data1 = 10;
40 data2 = 10;
41
42 pthread_create(&t1, 0, thread1, 0);
43 pthread_create(&t2, 0, thread2, 0);
44
45 pthread_join(t1, 0);
46 pthread_join(t2, 0);
47
48 if (data1==16 && data2==5)
49 {
50 ERROR:
51 goto ERROR;
52 }
53
54 return 0;
55}
56
Note: See TracBrowser for help on using the repository browser.