source: CIVL/examples/translation/pthread/sync01_true.c@ 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: 954 bytes
RevLine 
[bf46837]1/**
2* This program is taken from the Pthread benchmarks of SV-COMP 2014.
3* https://svn.sosy-lab.org/software/sv-benchmarks/tags/svcomp14/
4*/
5
[5fb1a47]6#include <stdio.h>
7#include <pthread.h>
8
9int num;
10
11pthread_mutex_t m;
12pthread_cond_t empty, full;
13
14void * thread1(void * arg)
15{
16 pthread_mutex_lock(&m);
17
18 while (num > 0)
19 pthread_cond_wait(&empty, &m);
20
21 num++;
22
23 pthread_mutex_unlock(&m);
24 pthread_cond_signal(&full);
25}
26
27
28void * thread2(void * arg)
29{
30 pthread_mutex_lock(&m);
31
32 while (num == 0)
33 pthread_cond_wait(&full, &m);
34
35 num--;
36
37 pthread_mutex_unlock(&m);
38
39 pthread_cond_signal(&empty);
40}
41
42
43int main()
44{
45 pthread_t t1, t2;
46
47 num = 1;
48
49 pthread_mutex_init(&m, 0);
50 pthread_cond_init(&empty, 0);
51 pthread_cond_init(&full, 0);
52
53 pthread_create(&t1, 0, thread1, 0);
54 pthread_create(&t2, 0, thread2, 0);
55
56 pthread_join(t1, 0);
57 pthread_join(t2, 0);
58
59 if (num!=1)
60 {
61 ERROR: goto ERROR;
62 ;
63 }
64
65 return 0;
66
67}
Note: See TracBrowser for help on using the repository browser.