多线程c exe崩溃但不在vs2013调试中

时间:2015-02-28 17:12:42

标签: c multithreading dll

使用Visual Studio 2013 Express,我在c中开发了一个多线程dll,以及一个使用了一些dll函数的关联exe。只要我从VS IDE(本地Windows调试器)中启动exe,一切正常;但是,当从命令行运行exe时,dll崩溃。通过从IDE中附加到正在运行的exe,我可以看到崩溃始终发生在WaitForMultipleObjects()调用,但这确实没有多大帮助,因为生成的线程的堆栈跟踪在ntdll内部丢失。 dll。

下面是dll代码片段,我该如何隔离并修复问题? 谢谢!

for (pr_id=0; pr_id<pBestPredictorsCount; pr_id++){
    arg[FH][pr_id]->OutputType = FH;
    arg[FH][pr_id]->CBaseVal = CRec[0].High;
    arg[FH][pr_id]->PredictorId = pr_id;
    arg[FH][pr_id]->Delta = vDelta;
    arg[FH][pr_id]->Scale = vHpScale;
    arg[FH][pr_id]->DebugLevel = pDebugLevel;
    arg[FH][pr_id]->LogFile = pLogFile;
    arg[FH][pr_id]->TotalBars = pTotalBars;
    arg[FH][pr_id]->PredictionLen = pPredictionLen;
    arg[FH][pr_id]->Forecast = oForecast;
    arg[FH][pr_id]->ChrMutex = ChrMutex;
    arg[FH][pr_id]->CVal = vCVal[FH];
    arg[FH][pr_id]->HVal = vHVal[FH];
    handle[ThreadCount] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)DoGATrainAndRun,
                          (void*)arg[FH][pr_id], 0, &th_id);
    ThreadCount++;

    arg[FL][pr_id]->OutputType = FL;
    arg[FL][pr_id]->CBaseVal = CRec[0].High;
    arg[FL][pr_id]->PredictorId = pr_id;
    arg[FL][pr_id]->Delta = vDelta;
    arg[FL][pr_id]->Scale = vHpScale;
    arg[FL][pr_id]->DebugLevel = pDebugLevel;
    arg[FL][pr_id]->LogFile = pLogFile;
    arg[FL][pr_id]->TotalBars = pTotalBars;
    arg[FL][pr_id]->PredictionLen = pPredictionLen;
    arg[FL][pr_id]->Forecast = oForecast;
    arg[FL][pr_id]->ChrMutex = ChrMutex;
    arg[FL][pr_id]->CVal = vCVal[FL];
    arg[FL][pr_id]->HVal = vHVal[FL];
    handle[ThreadCount] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)DoGATrainAndRun,
                          (void*)arg[FL][pr_id], 0, &th_id);
    ThreadCount++;
}

WaitForMultipleObjects(ThreadCount, handle, TRUE, INFINITE);
for (i = 0; i < ThreadCount; i++)
    CloseHandle(handle[i]);

1 个答案:

答案 0 :(得分:-1)

根据我之前的评论,我安装了MS Visual C ++ 2010 Express,从头开始重新创建项目,然后重新编译它。 这确实解决了我的问题,因为我的.exe现在运行完美。 正如我所怀疑的那样,崩溃的根本原因就在于VS2013库,也许是MSVCRT120(D).dll,但是我会把它留给其他人解决。