且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

.exe 0xC0000005访问冲突中的未处理异常

更新时间:2021-08-10 02:56:38

在调试器中单步执行代码时会看到什么?
What do you see when you step through your code in the debugger?


此调用是直接的调用线程管理器(非线程安全!):
This call is a direct call to the thread manager (non-thread safe!):
m_pool->OnThreadFinished(this);



它一定会引起问题,因为您实际上在其中DeleteIdleThread()(尝试删除调用该方法的线程).完成此操作并等待同步信号后,在MFC中执行此操作的正确方法是PostMessage().如果您不使用MFC,则只需查找非阻塞线程调用和/或同步方法,以了解您的框架碰巧是什么.



Its bound to cause problems because you actually DeleteIdleThread() within it (you try to delete the thread that called the method). The proper way of doing this within MFC would be to PostMessage() when you''re done and wait for a synchronization signal. If you''re not using MFC, just look up non-blocking thread calls and/or synchronization methods for whatever your framework happens to be.


我已经找到了问题,它'' s我的错,在函数CreateIdleThread中发现错误,该函数用于在必要时动态创建空闲线程:

void CThreadPool :: CreateIdleThread(const int num)
{
I have found the problem,It''s my fault,error was found in function CreateIdleThreadused to create idle threads dynamicly when necessary:

void CThreadPool::CreateIdleThread(const int num)
{
for (int i=0;i<num;i++)
    {
        Thread *thr = new Thread(/*here I forgot to pass pointer this */);       

        AppendToIdleList(thr);
        m_VarMutex.Lock();
        m_nAvailNum++;
        m_VarMutex.Unlock();
        printf("\t\tCreate %d Idle thread . All=%d, busy=%d,Idle=%d\n",num,m_ThreadList.size(),m_BusyList.size(),m_IdleList.size());

        printf("*** Thanks a lot and best regards to all of you !! ^|^ ***\n");
   }



}



}