调试时的 WaitForSingleObject(调试期间普遍缓慢)

发布于 2024-10-27 11:22:59 字数 339 浏览 1 评论 0原文

我必须说我了解很多有关线程的知识,但有一些东西让我发疯。

我曾经使用 Windows API 函数 WaitForSingleObject 来等待线程,它工作得很好。但是,当我调试代码时,WaitForSingleObject 似乎非常非常非常慢(它挂起很多)。但是当我在没有调试的情况下运行我的应用程序时,WaitForSingleObject 非常非常快。

为什么会发生这种情况?是因为IDE发送的消息吗?还是因为编译器的原因?

这对我影响不大。我只是觉得这个问题真的很烦人。

编辑:我正在使用Delphi 2010。

I must say I know a lot of things about threads, but theres something that is driving me crazy.

I use to wait for a thread using the Windows API function WaitForSingleObject and it works fine. But, when i am debugging my code, it seems that WaitForSingleObject is very, very, very slow (it hangs a lot). But when I am just running my app without debug, WaitForSingleObject is very, very fast.

Why does this happen? Is it because of Messages that the IDE sends? Or is it because of the compiler?

This is not affecting me a lot. I just think this issue is really annoying.

Edit: I am using Delphi 2010.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

霞映澄塘 2024-11-03 11:22:59

我真的怀疑 WaitForSingleObject 实际上是唯一变慢的东西。相反,当您在调试状态下运行时,几乎所有事情都可能会变慢。

我发现,不仅仅是 Win32 API 调用、对 OutputdebugString 的调用以及 IDE 选择在事件视图中记录的任何内容,实际上,因为这些事件或输出消息的大量负载会减慢 IDE、调试器的速度,因此我正在调试很多程序。

尝试关闭配置菜单中的事件视图复选框,看看一切是否变得更快。

它在“工具”->“选项,如图像中的 OP 所示,我也在这里添加了这些选项,以便于访问:
在此处输入图像描述

I really doubt that WaitForSingleObject is in fact the ONLY thing that gets slower. Rather, it is probable that almost everything gets slower, when you run with debugging on.

I find that far more than Win32 API calls, calls to OutputdebugString slow me down, and anything that the IDE chooses to log in the event view, really, because a big load of these event or output messages, slows the IDE, the debugger, and thus the program that I'm debugging, a lot.

Try turning off the event view checkboxes in the configuration menu and see if EVERYTHING gets faster.

It's in Tools -> Options, as shown by the OP in his image, which I've also added here, for handy access:
enter image description here

何其悲哀 2024-11-03 11:22:59

添加更多内存:) 您的机器可能不是那么强大。我也遇到过类似的问题,不过我用的是vs2010。无论如何,原理是相同的:在调试模式下运行会增加编译器向代码添加的检查的开销,并从环境本身转移开销,环境本身必须管理线程、资源和您想要查看的情况的内容。

PS:是什么让您认为问题出在 Wait* 函数上?您是否制作了一个使用 Wait* 且行为相同的简单应用程序?

Add more ram :) you probably have a not so powerful machine. I had a similar problem but using vs2010. Anyway the principles are the same: Running in debug mode adds an overhead from the checks added by compiler to the code and move overhead from the environment itself that must manages threads, resources and stuff for the case you want to see them.

PS: What makes you think the problem are the Wait* functions ? Have you made a simple application that use Wait* and behaves the same ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文