Windows API安全终止线程 [英] Windows API safe termination of thread

查看:506
本文介绍了Windows API安全终止线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows XP上有Delphi应用程序.此应用程序可使用100个线程.在某些情况下,我必须使用完全掉落的线程堆栈来终止线程.

I have Delphi application on windows XP. This application works with 100 threads. At some cases i have to terminate thread with fully drops of thread's stack.

我从WinAPI寻找功能,例如 terminatethread ,但这并不安全,并且: Windows Server 2003和Windows XP/2000 :目标线程的初始堆栈未释放,从而导致资源泄漏.

I looking for function from WinAPI like terminatethread but it not safelly and: Windows Server 2003 and Windows XP/2000: The target thread's initial stack is not freed, causing a resource leak.

推荐答案

没有此类功能.可能没有这样的功能. Windows可能无法知道该线程将整理哪些资源,并且它也不知道该如何处理.那就是您的应用程序的责任.

There's no such function. No such function could possibly exist. Windows cannot possibly know which resources are to be tidied up by that thread, and it couldn't know how to do so. That is the responsibilty of your app.

在我看来,您的做法是错误的.您应该在不使用强制的情况下以合作方式终止线程.任何其他事情都必定会导致泄漏以及最可能的其他更严重的问题.

It sounds to me like your are going about this the wrong way. You ought to be terminating the thread in a co-operative fashion without using force. Anything else is bound to lead to leaks and most likely other more serious problems.

这篇关于Windows API安全终止线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆