线程的析构函数为什么不执行
__fastcall CCLTP::CCLTP(bool CreateSuspended,AnsiString FileName,int Method)
: TThread(CreateSuspended)
{
this->FileName=FileName;
this->Method=Method;
this->strFileName=ExtractFileName(FileName);
this->strFilePath=ExtractFilePath(FileName);
aFileName="";
bFileName="";
g_pCLInfo=new CLInfo;
TMultiReadExclusiveWriteSynchronizer *section=new TMultiReadExclusiveWriteSynchronizer();
section->BeginWrite();
CLInfoCount++;
section->EndWrite();
delete section;
g_pCLInfo->HPHM="-" ;
g_pCLInfo->HPZL="" ;
g_pCLInfo->HPYS="无" ;
g_pCLInfo->WFXW="" ;
g_pCLInfo->DYCD="";
g_pCLInfo->XHDZT="-" ;
g_pCLInfo->SRSC="-" ;
g_pCLInfo->SFWZ="-";
}
__fastcall CCLTP::~CCLTP()
{
delete g_pCLInfo;
TMultiReadExclusiveWriteSynchronizer *section=new TMultiReadExclusiveWriteSynchronizer();
section->BeginWrite();
CLInfoCount--;
section->EndWrite();
delete section;
}
当执行完Execute后,为什么不会进入~CCLTP()?
谢谢
: TThread(CreateSuspended)
{
this->FileName=FileName;
this->Method=Method;
this->strFileName=ExtractFileName(FileName);
this->strFilePath=ExtractFilePath(FileName);
aFileName="";
bFileName="";
g_pCLInfo=new CLInfo;
TMultiReadExclusiveWriteSynchronizer *section=new TMultiReadExclusiveWriteSynchronizer();
section->BeginWrite();
CLInfoCount++;
section->EndWrite();
delete section;
g_pCLInfo->HPHM="-" ;
g_pCLInfo->HPZL="" ;
g_pCLInfo->HPYS="无" ;
g_pCLInfo->WFXW="" ;
g_pCLInfo->DYCD="";
g_pCLInfo->XHDZT="-" ;
g_pCLInfo->SRSC="-" ;
g_pCLInfo->SFWZ="-";
}
__fastcall CCLTP::~CCLTP()
{
delete g_pCLInfo;
TMultiReadExclusiveWriteSynchronizer *section=new TMultiReadExclusiveWriteSynchronizer();
section->BeginWrite();
CLInfoCount--;
section->EndWrite();
delete section;
}
当执行完Execute后,为什么不会进入~CCLTP()?
谢谢
...全文
相关推荐
《当析构函数遇到多线程》PPT
这是陈硕在 2009 年上海 C++ 技术大会演讲《当析构函数遇到多线程》的 PPT 投影片,可自由用于个人学习,其他使用需得到作者许可。 简介:编写线程安全的类不是难事,用同步原语保护内部状态即可。但是对象的生与死不能由对象自身拥有的互斥器来保护。如何保证即将析构对象 x 的时候,不会有另一个线程正在调用 x 的成员函数?或者说,如何保证在执行 x 的成员函数期间,对象 x 不会在另一个线程被析构?如何避免这种 race condition 是 C++ 多线程编程面临的基本问题,可以借助 tr1 中的 shared_ptr 和 weak_ptr 完美解决。这也是实现线程安全的 Observer 模式的必备技术。
当析构函数遇到多线程
当析构函数遇到多线程
StringBuilder为什么线程不安全深入讲解
主要给大家介绍了关于StringBuilder为什么线程不安全的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用StringBuilder线程具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
浅谈Java StringBuilder为什么线程不安全
主要介绍了浅谈Java StringBuilder为什么线程不安全,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
Java多线程--让主线程等待所有子线程执行完毕在执行
Java主线程等待所有子线程执行完毕在执行,其实在我们的工作中经常的用到,本篇文章就介绍了Java多线程--让主线程等待所有子线程执行完毕在执行,有需要的可以了解一下。



