Linux???????????sleep???????
???????????? ???????[ 2012/8/29 10:50:00 ] ????????
???????????????????????????????????????sleep()???????????????????????????????????????Ч??????????????????????
????1??usleep
?????????????????????????????????????????????????????????????????????????????????????????
????2??select
????????????????ù????????????????????
????3??pthread_cond_timedwait
????????pthread_cond_timedwait(pthread_cond_t* cond?? pthread_mutex_t *mutex?? const struct timespec *abstime)???????????????????????????????cond???????????????????????????????cond?????????????????????????????????demo??
?????????????δ???thr_fn????????????
#include <stdio.h>
#include <stdlib.h>
int flag = 1;
void * thr_fn(void * arg) {
while (flag){
printf("******
");
sleep(10);
}
printf("sleep test thread exit
");
}
int main() {
pthread_t thread;
if (0 != pthread_create(&thread?? NULL?? thr_fn?? NULL)) {
printf("error when create pthread??%d
"?? errno);
return 1;
}
char c ;
while ((c = getchar()) != 'q');
printf("Now terminate the thread!
");
flag = 0;
printf("Wait for thread to exit
");
pthread_join(thread?? NULL);
printf("Bye
");
return 0;
}
????????q???????????sleep??????????????????????????????????????10s???????join??????sleep???????????????????
??????
???·???
??????????????????
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