main函数与其创建的线程的关系

main函数及其主线程退出时候,其创建的子线程也会跟着退出,要想不退出需要在子线程创建后面加上回收代码

点击查看代码
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
//#include <sys/mman.h>
//#include <sys/types.h>
//#include <sys/ioctl.h>
//#include <sys/stat.h>
//#include <fcntl.h>
//#include <pthread.h>
//#include <errno.h>
//#include <string.h>

#define min_t(x,y) 0

int uio_thread()
{
	printf("=================================\n");
	printf("thread is ok!\n");
	//while(1)
	{
		//printf("-----------------------\n");
	}
	return 0;
}

int main(int argc, char* argv[])
{	
	printf("--0x%x--%d\n",12,12);
		
	pthread_t my_thread;
        int ret = pthread_create(&my_thread, NULL, &uio_thread, NULL);  
        if(ret != 0)  
        {  
            printf("Create pthread error!\n");  
            return -1;  
        }

	pthread_join(my_thread,NULL);
	
	//while(1)
	//{
		//printf("########################\n");
	//}
	return 0;
}
posted @ 2021-12-28 11:11  上官鸿信の  阅读(127)  评论(0编辑  收藏  举报