source: CIVL/examples/translation/pthread/lazy01_false.c@ 09bc145

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since 09bc145 was 09bc145, checked in by John Edenhofner <johneden@…>, 12 years ago

Added unchanged competition examples

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

  • Property mode set to 100644
File size: 709 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}
13
14
15void *thread2(void *arg)
16{
17 pthread_mutex_lock(&mutex);
18 data+=2;
19 pthread_mutex_unlock(&mutex);
20}
21
22
23void *thread3(void *arg)
24{
25 pthread_mutex_lock(&mutex);
26 if (data >= 3){
27 ERROR: goto ERROR;
28 ;
29 }
30 pthread_mutex_unlock(&mutex);
31}
32
33
34int main()
35{
36 pthread_mutex_init(&mutex, 0);
37
38 pthread_t t1, t2, t3;
39
40 pthread_create(&t1, 0, thread1, 0);
41 pthread_create(&t2, 0, thread2, 0);
42 pthread_create(&t3, 0, thread3, 0);
43
44 pthread_join(t1, 0);
45 pthread_join(t2, 0);
46 pthread_join(t3, 0);
47
48 return 0;
49}
Note: See TracBrowser for help on using the repository browser.