Linux???????????????
???????????? ???????[ 2014/2/27 9:39:19 ] ????????Linux ?????? ????????
????????????????????????????????????????????????????????????????????????????????????????????????? ??????????????????????????
?????????????????? pthread_cond_init
???????????? pthread_cond_destroy
??????? pthread_cond_wait
????????????????????????? pthread_cond_signal
???????????????????????????????????????????????????????????????????????
#include <stdio.h>
#include <pthread.h>
#include <signal.h>
pthread_mutex_t m1?? m2;
pthread_cond_t c1??c2;
pthread_t t1?? t2?? t3;
void* r1(void *arg)
{
sleep(10); //???10??
pthread_cond_signal(&c1);
printf("t1 finish
");
while(1);
}
void* r2(void *arg)
{
sleep(15);//???15??
pthread_cond_signal(&c2);
printf("t2 finish
");
while(1);
}
void* r3(void *arg)
{
pthread_cond_wait(&c1?? &m1);
pthread_cond_wait(&c2?? &m2);
printf("finish
");//15????????
}
main()
{
pthread_mutex_init(&m1?? 0);
pthread_mutex_init(&m2?? 0);
pthread_cond_init(&c1?? 0);
pthread_cond_init(&c2?? 0);
pthread_create(&t1?? 0?? r1?? 0);
pthread_create(&t2?? 0?? r2?? 0);
pthread_create(&t3?? 0?? r3?? 0);
while(1);
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11