线程提前终止代码255
Thread Terminating Early with Code 255
我正在尝试在线程中运行我的程序的一部分,并得到一个不寻常的结果。
我已经用Remus建议的更改结果更新了这个问题,但由于我仍然得到一个错误,我觉得这个问题仍然是开放的。
我已经在一个dll中实现了一些功能,以绑定到一个供应商的软件中。一切工作,直到我试图在这个dll中创建一个线程。
这是DLL的相关部分:
extern "C" {
__declspec(dllexport) void __cdecl ccEntryOnEvent(WORD event);
}
定义供应商的软件调用的函数,然后:
using namespace std;
HANDLE LEETT_Thread = NULL;
static bool run_LEETT = true;
unsigned threadID;
void *lpParam;
int RunLEETTThread ( void ) {
LEETT_Thread = (HANDLE)_beginthreadex( NULL, 0, LEETT_Main, lpParam, 0 , &threadID );
//LEETT_Thread = CreateThread ( NULL, 0, LEETT_Main, lpParam, 0 , NULL );
if ( LEETT_Thread == NULL )
ErrorExit ( _T("Unable to start translator thread") );
run_LEETT = false; // We only wish to create the thread a single time.
return 0;
}
extern "C" void __cdecl ccEntryOnEvent(WORD event ) {
switch (event) {
case E_START:
if ( run_LEETT ) {
RunLEETTThread ();
MessageText ( "Running LEETT Thread" );
}
break;
}
WaitForSingleObject( LEETT_Thread ,INFINITE);
return;
}
函数声明为
unsigned __stdcall LEETT_Main ( void* lpParam ) {
LEETT_Main在没有优化的情况下编译为独立可执行文件时约为136k(我有一个单独的文件,其中包含main(),调用与myFunc相同的函数)。
在改变调用线程的方式之前,当声明一个包含std::list的结构时,程序会崩溃,如下所示:
struct stateFlags {
bool inComment; // multiline comments bypass parsing, but not line numbering
// Line preconditions
bool MCodeSeen; // only 1 m code per block allowed
bool GCodeSeen; // only 1 g code per block allowed
std::list <int> gotos; // a list of the destination line numbers
};
它现在在_beginthreadx命令上崩溃了,通过跟踪显示如下
/*
* Allocate and initialize a per-thread data structure for the to-
* be-created thread.
*/
if ( (ptd = (_ptiddata)_calloc_crt(1, sizeof(struct _tiddata))) == NULL )
goto error_return;
通过跟踪,我看到了一个错误252(坏ptr)和255(运行时错误)。
我想知道是否有人遇到过这种行为创建线程(在dll ?)和补救措施可能是什么。当我在我的小程序中创建这个结构的实例时,没有任何问题。当我删除list变量时,程序只是在声明字符串
时在其他地方崩溃了。在这一点上,我非常愿意接受建议,如果我必须的话,我现在会删除线程的想法,尽管它不是特别实用。
谢谢,特别是那些再次阅读这篇文章的人:)
使用CRT (std::list
意味着CRT)的线程需要用_beginthreadx创建,如MSDN上的文档所示:
可执行程序中调用C运行时库(CRT)的线程应该为线程使用_beginthreadx和_endthreadx函数吗管理而不是CreateThread和ExitThread;
不清楚你如何启动你的线程,但似乎你在DllMain中这样做,这是不推荐的(参见从DllMain创建线程会死锁吗?)。
在重新检查这里的注释和项目配置时,供应商提供的解决方案文件使用/MTd进行调试,但我们正在构建一个DLL,所以我需要使用/MDd,它立即编译并正确运行。
很抱歉,这是一个可笑的挠头…
- 为什么这个 c++ 代码打印出长度 5,当我打印出字符串时,程序会自动终止?
- 用于将C++代码转换为 Web 程序集的脚本未终止
- 运行代码时,c++ 会终止进程
- 如何改进我的代码,使其不会因超时而终止?(黑客排名挑战)
- VSCode C++终端进程已终止,退出代码为:1
- 代码在执行之前终止,并且没有从用户那里获取输入
- 终端进程终止,退出代码为:1有什么方法可以修复它吗
- linux mint进程上的代码块已终止,状态为-1
- 终止调用本机代码的 .Net 线程
- 当我输入非整数值时,我的二次方程代码终止,如何让它正确循环?
- 以下代码如何工作以及何时终止
- 为什么我的 C++ 应用以退出值 -1 终止,但某些代码逻辑未执行?
- 这段代码出了什么问题?它在第二个 cin 可以执行之前终止
- 我的链接列表程序在代码块编译器(X0000000005)中以状态-1073741819终止
- 声明终止cpp中的以下代码中出现错误
- Jni_createjavm()用退出代码1终止
- C++ WinSock Recv 在接收 0 数据时终止线程而不是返回错误代码
- 使用终止进程终止"mstsc.exe"进程时出现错误代码(5)访问被拒绝
- 模拟终止,退出代码:132
- 如何使用 c++ 代码终止在不同用户下运行的进程