8
pthread_t thread1, thread2, thread3;
10
void *tfunc1(void *attr) {
11
pthread_mutex_lock(&mutex);
14
printf("wait1 finished\n");
15
pthread_cond_wait(&cond,&mutex);
16
pthread_mutex_unlock(&mutex);
21
void *tfunc2(void *attr) {
22
pthread_mutex_lock(&mutex);
25
printf("wait2 finished\n");
26
pthread_cond_wait(&cond,&mutex);
27
pthread_mutex_unlock(&mutex);
32
void *tfunc3(void *attr) {
34
pthread_mutex_lock(&mutex);
35
printf("locked for send\n");
36
pthread_cond_broadcast(&cond);
38
pthread_mutex_unlock(&mutex);
39
printf("unlocked from send\n");
47
pthread_mutex_init(&mutex,NULL);
48
pthread_cond_init(&cond,NULL);
50
pthread_create(&thread1,NULL,tfunc1,NULL);
51
pthread_create(&thread2,NULL,tfunc2,NULL);
52
pthread_create(&thread3,NULL,tfunc3,NULL);
54
pthread_join(thread1,&ret);
55
pthread_join(thread2,&ret);
56
pthread_join(thread3,&ret);