printf("Process will exit when new pthread is over\n"); //等待线程pId的完成 pthread_join(pId,NULL); printf("Process exit\n");
return0;
}
编译的时候要加上-lpthread, 运行结果如下:
1 2 3 4 5 6 7 8 9 10
Process running ,count : 0 New pthread running ,count: 0 Process running ,count : 1 New pthread running ,count: 1 Process running ,count : 2 New pthread running ,count: 2 Process will exit when new pthread is over New pthread running ,count: 3 New pthread running ,count: 4 Process exit