我使用CWinThread m_pThread
创建了一个AfxBeginThread()
对象。然后我需要消灭它。经过一些操作后,我需要再次创建线程。我再次打电话给AfxBeginThread()
。
我收到了消息this may be due to corruption of the heap...
。我没有在线程中做任何测试。我仍然发现了这个错误。
我通过这些破坏了线程。
enter code here
bool bRet = TerminateThread(m_pThread->m_hThread, -1);
delete m_pThread;
m_pThread->m_hThread = NULL;
m_pThread = NULL;
答案 0 :(得分:0)
如果要控制线程的生命周期,请确保关闭m_bAutoDelete,例如
m_pThread = AfxBeginThread( DoWork, NULL, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED );
if ( m_pThread ) {
m_pThread->m_bAutoDelete = FALSE;
m_pThread->ResumeThread();
}