linux为什么创建线程后主程序退出了

2025-05-15 03:08:50
推荐回答(1个)
回答(1):

main()主程序里创建一个新线程:
(void*) thread2;
pthread_t id2;
main(){

ret=pthread_create(&id,NULL,(void*) thread,NULL);
if (ret!=0)
{
printf("Create pthread error!\n");
exit (1);
}
//第二个线程
ret=pthread_create(&id2,NULL,(void*) thread2,NULL);
if (ret!=0)
{
printf("Create pthread2 error!\n");
exit (1);