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

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

Updated examples

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

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