source: CIVL/examples/translation/pthread/sync01_true.cvl@ 50f834b

1.23 2.0 main test-branch
Last change on this file since 50f834b was bf46837, checked in by Manchun Zheng <zmanchun@…>, 12 years ago

added comments.

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

  • Property mode set to 100755
File size: 1007 bytes
Line 
1/**
2* This is a translation of a Pthread program from
3* the Pthread benchmarks of SV-COMP 2014.
4* https://svn.sosy-lab.org/software/sv-benchmarks/tags/svcomp14/
5*
6* Command line execution:
7* civl verify sync01_true.cvl
8*/
9
10#include <civlc.h>
11#include "pthread.cvh"
12
13int num;
14pthread_mutex_t m;
15pthread_cond_t empty, full;
16
17void *thread1(void*arg)
18{
19 pthread_mutex_lock(&m);
20
21 while (num > 0)
22 pthread_cond_wait(&empty, &m);
23
24 num++;
25
26 pthread_mutex_unlock(&m);
27 pthread_cond_signal(&full);
28}
29
30
31void *thread2(void*arg)
32{
33 pthread_mutex_lock(&m);
34
35 while (num == 0)
36 pthread_cond_wait(&full, &m);
37
38 num--;
39
40 pthread_mutex_unlock(&m);
41
42 pthread_cond_signal(&empty);
43}
44
45
46void main()
47{
48 pthread_t t1, t2;
49
50 num = 1;
51
52 pthread_mutex_init(&m, 0);
53 pthread_cond_init(&empty, 0);
54 pthread_cond_init(&full, 0);
55
56 pthread_create(&t1, 0, thread1, 0);
57 pthread_create(&t2, 0, thread2, 0);
58
59 pthread_join(t1, 0);
60 pthread_join(t2, 0);
61
62 if (num!=1)
63 {
64 $assert($false);
65 }
66}
Note: See TracBrowser for help on using the repository browser.