source: CIVL/examples/pthread/esbmc/sync01_true.c@ beab7f2

main test-branch
Last change on this file since beab7f2 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

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

  • Property mode set to 100644
File size: 854 bytes
Line 
1extern void __VERIFIER_error();
2
3#include <stdio.h>
4#include <pthread.h>
5
6int num;
7
8pthread_mutex_t m;
9pthread_cond_t empty, full;
10
11void * thread1(void * arg)
12{
13 pthread_mutex_lock(&m);
14
15 while (num > 0)
16 pthread_cond_wait(&empty, &m);
17
18 num++;
19
20 pthread_mutex_unlock(&m);
21 pthread_cond_signal(&full);
22}
23
24
25void * thread2(void * arg)
26{
27 pthread_mutex_lock(&m);
28
29 while (num == 0)
30 pthread_cond_wait(&full, &m);
31
32 num--;
33
34 pthread_mutex_unlock(&m);
35
36 pthread_cond_signal(&empty);
37}
38
39
40int main()
41{
42 pthread_t t1, t2;
43
44 num = 1;
45
46 pthread_mutex_init(&m, 0);
47 pthread_cond_init(&empty, 0);
48 pthread_cond_init(&full, 0);
49
50 pthread_create(&t1, 0, thread1, 0);
51 pthread_create(&t2, 0, thread2, 0);
52
53 pthread_join(t1, 0);
54 pthread_join(t2, 0);
55
56 if (num!=1)
57 {
58 ERROR: __VERIFIER_error();
59 ;
60 }
61
62 return 0;
63
64}
65
Note: See TracBrowser for help on using the repository browser.