程序运行一段时间(时间不定,可能一天也可能几个小时),没有任何提示自动退出.请问造成这种情况一般有那些可能性?极为纳闷
---------------------------
补充说明:
(1)该程序的正常关闭过程:是需要输入用户名密码,验证正确后,通知线程推出,在规定的时间内所有线程都退出后,才关闭程序.
(2)当此程序用串口和井下通讯的时候,只有两个线程,程序运转一直很正常.
(3)当进行网络通讯时开了10个线程,进行处理通讯环节问题.出现描述的问题.
(4)第二和第三的唯一区别是通讯方式不一样,数据的接收和串口不一致.程序其他环节完全一致.
(5)程序开发环境vc2003+windows2003 standarad edition
(6)程序运行环境:win2000server+sp4 (4cpu,2G内存)
good luck!
void __declspec(naked) __fastcall __security_check_cookie(UINT_PTR cookie)
{
/* x86 version written in asm to preserve all regs */
__asm {
cmp ecx, __security_cookie
jne failure
rep ret /* REP to avoid AMD branch prediction penalty */
failure:
jmp __report_gsfailure
}
}Try to enable Dr Waston on your system:http://support.microsoft.com/default.aspx?scid=kb;EN-US;308538
这是我用Drwtsn32.exe工具找出来的错误日志:
但这所列出的时间不对,不是我程序退出的时间.而且进程也不对.
发生应用程序意外错误:
应用程序: explorer.exe (pid=316)
时间: 2006-3-23 @ 19:18:13.718
意外情况编号: c0000005 (访问侵犯)*----> 系统信息 <----*
计算机名: KJRY
用户名: Administrator
处理器数量: 4
处理器类型: x86 Family 15 Model 4 Stepping 1
Windows 2000 版本: 5.0
当前内部版本号: 2195
Service Pack: 4
当前类型: Multiprocessor Free
注册的单位: ymjt
注册的所有者: ky*----> 任务列表 <----*
0 Idle.exe
8 System.exe
180 smss.exe
208 csrss.exe
228 winlogon.exe
256 services.exe
268 lsass.exe
436 svchost.exe
464 CCenter.exe
480 Ravmond.exe
520 spoolsv.exe
552 msdtc.exe
736 svchost.exe
764 llssrv.exe
....
从出错的时候调试环境的调用堆栈来看,问题可以锁定在OnTimer上视图.请各位帮我看看这段代码有什么问题没:
void CPepoleOrientationView::OnTimer(UINT nIDEvent)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if(nIDEvent==1)
{
CString m_str[9];
int k; for(int i=0;i<MAX_STATION_NUMBER;i++)
{
if(PointDefine[i].m_iStationNumber!=0)
{ //初始化列表视图信息
for(int kk=0;kk<9;kk++)
{
m_str[kk]=_T(" ");
}
m_str[0].Format("第%03d组",PointDefine[i].m_iGroupNumber);
m_str[1].Format("%03dR00",PointDefine[i].m_iStationNumber);
m_str[2].Format("%s",PointDefine[i].m_strIPAddress);
m_str[3].Format("%s",PointDefine[i].m_strSetupAddress);
m_str[4].Format("%s",GetStationType(PointDefine[i].m_iStationType));
m_str[5].Format("%s", GetStationStatus(PointDefine[i].StationStatus));
for(k=0;k<MAX_STATION_NUMBER;k++)
{
if(DeviceCommandCode[k].StationNumber==PointDefine[i].m_iStationNumber)
{
m_str[6].Format("%d",DeviceCommandCode[k].CommTotalNumber);
m_str[7].Format("%s",DeviceCommandCode[k].m_strLatelyExeCptionTime);
break;
}
}
m_str[8]=GetDBStatusIndex(gDBStatusIndex);
int cc=m_cListCtrl.GetItemCount();
for(int m_k=0;m_k<m_cListCtrl.GetItemCount();m_k++)
{
if(atoi(m_cListCtrl.GetItemText(m_k,1))==PointDefine[i].m_iStationNumber)
{
m_cListCtrl.SetItemText(m_k,5,m_str[5]);
m_cListCtrl.SetItemText(m_k,6,m_str[6]);
m_cListCtrl.SetItemText(m_k,7,m_str[7]);
m_cListCtrl.SetItemText(m_k,8,m_str[8]); break; }
}
if(m_k>=m_cListCtrl.GetItemCount())
m_cListCtrl.InsertItem(0,m_str[0],m_str[1],m_str[2],m_str[3],m_str[4],m_str[5],m_str[6],m_str[7],m_str[8]);
}
}
} CFormView::OnTimer(nIDEvent);
}
At what line?
-----------------------------------------------
MyCSDN 免费版 - http://community.csdn.net/Expert/TopicView1.asp?id=4608614
在线程中已经加锁,但是在OnTimer中没有加
if(DeviceCommandCode[k].StationNumber==PointDefine[i].m_iStationNumber)
{
m_str[6].Format("%d",DeviceCommandCode[k].CommTotalNumber); // 此时线程1写了DeviceCommandCode[k].CommTotalNumber,但明显m_str[6]的值已经过时了,是旧的值 // 这种错误如果发生在条件控制中,后果就无法预料了
}(以下签名由MyCSDN回复工具生成)
-----------------------------------------------
MyCSDN 免费版 - http://community.csdn.net/Expert/TopicView1.asp?id=4608614
2. cc is not used.
3. m_k name is confusing, and it should be moved outside of the for loop.
4. m_str[0] ... m_str[4] are always generated, but may be not used.
5. Why do you use Format("%s", X); Can you use X directly?
1) Are you compiling/linking with multi-thread libraries?
A:/MTd 多线程调试; 5. Why do you use Format("%s", X); Can you use X directly?
A: 可以直接使用X;
我现在将CString m_str[9];放到了视图类中声明.让他运转,看看是否还会重复问题.
感谢各位大哥的帮忙.希望能在你们帮助下,尽快搞定这事
-----------------------------------------------
MyCSDN 免费版 - http://community.csdn.net/Expert/TopicView1.asp?id=4608614
-------------------------------------------------------
MyCSDN - CSDN离线数据浏览工具。可下载论坛文件、文档文章和全文搜索论坛数据以供离线浏览。支持签名回复。
下载地址:http://nj.onlinedown.net/soft/6591.htm