编译后执行,结果如下 [root@localhost test]# gcc thread.c -o thread -lpthread [root@localhost test]# ./thread new thread : pid is 2442, tid is 4008711936 (0xeef01700) main thread : pid is 2442, tid is 4008711936 (0xeef01700) start sleep Segmentation fault (core dumped)
当我把程序中 sleep(5) 注释掉后编译执行正常,结果为 [root@localhost test]# gcc thread.c -o thread -lpthread [root@localhost test]# ./thread new thread : pid is 2830, tid is 2600584960 (0x9b01c700) main thread : pid is 2830, tid is 2600584960 (0x9b01c700) start sleep end
我不明白程序哪里出错了
而且 main thread的线程id,和新创建线程new thread 的线程id 相同, 按说应该不同的