首页 > 编程知识 正文

disseminate,can not get the information of

时间:2023-05-05 22:01:58 阅读:62517 作者:745

多线程程序通常很容易使用TerminateThread函数。 此函数的功能是用于结束工作的线程。 在MSDN上,REMARKS说:

terminatethreadisusedtocauseathreadtoexit.whenthisoccurs, thetargetthreadhasnochancetoexecuteanyuser-mode code.dllsattachedtothethreadarenotnotifiedthatthethreadisterminating.thesthethreathreadination

windows server 2003 and windows XP/20003360 thetargetthread ' sinitial stackisnotfreed, causingaresourceleak.terminatethreadisadangerousfunctionthatshouldonlybeusedinthemostextremecases.youshouldcallterminateteterminateteteththh tthetargetthreadisdoing,andyoucontrolallofthecodethatthetargetthreadcouldpossiblyberunningatthetimeofthetermination.for exather

ifthetargetthreadownsacriticalsection,thecriticalsectionwillnotbereleased.ifthetargetthreadisallocatingmemoryfromtheheap, theheaplockwillnotbereleased.ifthetargetthreadisexecutingcertainkernel 32 callswhenitisterminated, the kernel32 stateforthethread ' sprocesscouldbeinconsistent.ifthetargetthreadismanipulatingtheglobalstateofashareddll,thesttate affectingotherusersofthedll.athreadcannotprotectitselfagainstterminatethread, otherthanbycontrollingaccesstoitshandles.thethreadhandlereturnedbythecreatethreadandcreateprocessfunctionshasthread _ termi

ifthetargetthreadisthelastthreadofaprocesswhenthisfunctioniscalled,thethread ' sprocessisalsoterminated。

thestateofthethreadobjectbecomessignaled,releasinganyotherthreadsthathadbeenwaitingforthethreadtoterminate.thethread ' steed

terminatingathreaddoesnotnecessarilyremovethethreadobjectfromthesystem.athreadobjectisdeletedwhenthelastthreadhandleisclosed

其中,如果目标线程进入临界区域,则TerminateThread会导致该线程无法释放。 这次项目中程序没有反应的问题是因为这个。

当线程运行malloc或free函数时,它将进入堆的临界区域。 此时,如果线程中断,其他线程将等待并僵硬。

此时进入程序调用堆栈,可以看到很多线程死亡的free和malloc的内部。

所以要结束线程,最好不要用这个函数中断。

转载于:https://www.cn blogs.com/Ming xx/archive/2011/06/25/2089954.html

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。