【发布时间】:2012-06-01 07:59:58
【问题描述】:
我正在尝试编写一个 Teamcenter ITK 程序,该程序将作为从主线程调用的不同线程运行。从 UI 上的操作调用主线程。由于子线程需要大量时间才能完成,如果我不创建子线程并将代码放在主线程中,UI最多会冻结10分钟,这是不可接受的。
主线程和子线程都需要共享由主线程完成的身份验证,因为我使用的是 SSO。他们还需要连接到数据库。最后,主线程不应该等待子线程完成,否则拥有子线程的整个目的将被破坏。
调用子线程的代码如下:
handle = (HANDLE) _beginthread (submitToPublishTibcoWf, 0, &input); // create thread
do
{
sprintf(message, "Waiting %d time for 1000 milliseconds since threadReady is %d\n", i++, threadReady);
log_msg(message);
WaitForSingleObject(handle, 1000);
}
while (!threadReady);
sprintf(message, "Wait for thread to be ready over after %d tries since threadReady is %d\n", i, threadReady);
log_msg(message);
log_msg("Main thread about to exit now");
每当我要在子线程中执行需要 8 分钟运行的代码时,我都会设置 threadReady = 1 全局变量。
问题是子线程在主线程退出后表现异常,我收到此错误:
Fri May 25 11:34:46 2012 : Main thread about to exit now
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
大部分子线程都会执行,但有时它会在最后崩溃。
【问题讨论】:
-
有时我在调试时也会收到此错误:tcserver.exe 中 0x580d8390 处的未处理异常:0xC0000005:访问冲突读取位置 0xffffffec。
标签: c multithreading teamcenter teamcenter-itk