Linux???????????????
???????????? ???????[ 2014/2/27 9:39:19 ] ????????Linux ?????? ????????
??????н??
???????????????????????????????????????????????????????????????
????????????У?????????????е???????????????
#include <pthread.h>
#include <stdio.h>
#include <signal.h>
pthread_t t1??t2;
pthread_mutex_t m1??m2;
pthread_cond_t c;
void *r1(void *d)
{
while(1)
{
pthread_mutex_lock(&m1);
printf("wait
");
pthread_cond_wait(&c??&m2);
pthread_mutex_unlock(&m1);
}
}
void *r2(void *d)
{
while(1)
{
pthread_mutex_lock(&m1);
printf("signal
");
pthread_cond_signal(&c);
pthread_mutex_unlock(&m1);
}
}
main()
{
pthread_cond_init(&c??0);
pthread_mutex_init(&m1??0);
pthread_mutex_init(&m2??0);
pthread_create(&t1??0??r1??0);
pthread_create(&t2??0??r2??0);
while(1);
/*
pthread_join(t1??0);
pthread_join(t2??0);
pthread_mutex_destroy(&m2);
pthread_mutex_destroy(&m1);
pthread_cond_destroy(&c);*/
}
??????н??????????е??????????????????????????
??????????????????????????????????????????????
#include <pthread.h>
#include <stdio.h>
#include <signal.h>
pthread_t t1??t2;
pthread_mutex_t m1??m2;
pthread_cond_t c;
void *r1(void *d)
{
while(1)
{
pthread_mutex_lock(&m1);
printf("wait
");
pthread_cond_wait(&c??&m1);
pthread_mutex_unlock(&m1);
}
}
void *r2(void *d)
{
while(1)
{
pthread_mutex_lock(&m1);
printf("signal
");
pthread_cond_signal(&c);
pthread_mutex_unlock(&m1);
}
}
main()
{
pthread_cond_init(&c??0);
pthread_mutex_init(&m1??0);
pthread_mutex_init(&m2??0);
pthread_create(&t1??0??r1??0);
pthread_create(&t2??0??r2??0);
while(1);
/*
pthread_join(t1??0);
pthread_join(t2??0);
pthread_mutex_destroy(&m2);
pthread_mutex_destroy(&m1);
pthread_cond_destroy(&c);*/
}
??????
???·???
??????????????????
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