linux中main()主程序里创建一个新线程后,还能再建个线程吗?

来源:百度知道 编辑:UC知道 时间:2024/05/01 20:26:10
main()主程序里创建一个新线程:
ret=pthread_create(&id,NULL,(void*) thread,NULL);
if (ret!=0)
{
printf("Create pthread error!\n");
exit (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);
}

}

你最多可以创建1024个线程