我的程序因检测到堆栈粉碎而失败,而我从 Valgring 收到的唯一消息是“块可能在丢失记录中丢失”重复了三遍,我不知道如何解决。
==3726== 144 bytes in 1 blocks are possibly lost in loss record 74 of 87
==3726== at 0x4025315: calloc (vg_replace_malloc.c:467)
==3726== by 0x4010CD7: allocate_dtv (dl-tls.c:300)
==3726== by 0x401146B: _dl_allocate_tls (dl-tls.c:464)
==3726== by 0x40405C6: pthread_create@@GLIBC_2.1 (allocatestack.c:570)
==3726== by 0x806BF36: Thread::Thread(void* (*)(void*), void*) (os.cpp:203)
这是代码,Valgrind 是 pthread_create 调用。
Thread::Thread( PFUNC func, void * arg )
{
int s = pthread_create( &_ThreadId, NULL, func, arg); //here is msg from valgrind
if (s != 0)
throw EXCEPT_NOTHREAD;
pthread_detach( _ThreadId );
}
请您帮我看看 Thread 函数有什么问题?我在其他类似的问题中读到 pthread_detach 必须在创建线程之前?提前非常感谢。