- 论坛徽章:
- 0
|
pthread_t *p p = (pthread_t *)malloc(num*sizeof(pthread_t))
然后for循环创建线程,在创建线程的过程中如果num不是特别大的话,是没有什么问题的,我这里设置成
500没有问题,大于500后就会出现段错误,我调试了core dump文件,内容如下:
warning: Corrupted shared library list: 0x7f329f0aa9f8 != 0x7f31bceb0700
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `./a.out -c 500 http://www.baidu.com/index.php'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 __tsearch (key=key@entry=0x7f3205f416f8, vrootp=vrootp@entry=0x7f3211f5a728,
compar=compar@entry=0x7f329e9c04a0 <known_compare>) at tsearch.c:251
251 tsearch.c: No such file or directory.
但是如果我要是在for循环创建线程的时候sleep(1)秒后就没有啥问题了,但是每次sleep(1)秒这样创建
线程太慢,另外一种情况就是如果改成pthread_t p[num]数组的形式然后for循环创建多线程就没有任何
问题了。 不知道有谁遇见过这样的问题。 |
|