source: CIVL/examples/pthread/sync01_true.cvl@ f6ce0eb

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

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

  • Property mode set to 100644
File size: 1.0 KB
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 return NULL;
29}
30
31
32void *thread2(void*arg)
33{
34 pthread_mutex_lock(&m);
35
36 while (num == 0)
37 pthread_cond_wait(&full, &m);
38
39 num--;
40
41 pthread_mutex_unlock(&m);
42
43 pthread_cond_signal(&empty);
44
45 return NULL;
46}
47
48
49void main()
50{
51 pthread_t t1, t2;
52
53 num = 1;
54
55 pthread_mutex_init(&m, 0);
56 pthread_cond_init(&empty, NULL);
57 pthread_cond_init(&full, NULL);
58
59 pthread_create(&t1, 0, thread1, 0);
60 pthread_create(&t2, 0, thread2, 0);
61
62 pthread_join(t1, 0);
63 pthread_join(t2, 0);
64
65 if (num!=1)
66 {
67 $assert($false);
68 }
69}
Note: See TracBrowser for help on using the repository browser.