include
#include
#include
static int run = 1;
static int retvalue;
void *start_routine(void *arg){
int *runing = arg;
printf("The child thread has been inited,the arg is: %d\n",*runing);
while(*runing){
printf("The child thread is runing !\n");
usleep(1);
}
printf("Exit child thread\n");
retvalue = 8;
pthread_exit((void *)&retvalue);
}
int main(void){
pthread_t pt;
int ret = -1;
int times = 3;
int i = 0;
int ret_join = NULL;
ret = pthread_create(&pt,NULL,(void)start_routine,&run);
if(ret !=0){
printf("Create thread fail!\n");
return 1;
}
usleep(1);
for(;i < times;i++){
printf("Print the main thread!\n");
usleep(1);
}
run = 0;
pthread_join(pt,(void*)&ret_join);
printf("The return of thread is %d\n",*ret_join);
return 0;
}
在子线程中,while循环是一个死循环,那个子线程如何退出终止的?各位大神,求解答!谢了各位!总是在线程这里玩儿不明白...