多线程引擎窗口随机减速

发布于 2024-08-04 16:43:23 字数 232 浏览 8 评论 0原文

我们设置了一个基于任务的多线程引擎,其中调度程序将任务传递到线程无锁队列。该引擎采用 C++ 语言,并使用 DirectX 进行渲染,我们使用 boost::thread 来创建线程。当处于窗口模式时,它会随机减慢一秒钟左右,然后再加速。看来这是 Vista 造成的,但我们不知道如何正确解决它。

我们尝试过的一件事似乎有助于解决随机减速问题,那就是在处理每个任务后让线程休眠一毫秒,但这会导致其他问题,而且并不是一个很好的解决方案。

We have a task based multithreaded engine set up where a scheduler passes the task to the threads lock-free queue. The engine is in C++ with DirectX for the rendering and we are using boost::thread for creating the threads. When in windowed mode, it randomly slows down for a second or so and then speeds back up. It seems that it's something that Vista seems to be causing, but we can't figure out how to solve it properly.

One thing that we tried that seemed to help with the random slowdowns was making the thread sleep for a millisecond after each task has been processed, but it causes other problems and isn't really a great solution.

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

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

发布评论

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

评论(2

吃兔兔 2024-08-11 16:43:23

我建议做的第一件事是通过分析了解导致速度减慢的原因。

进行随机睡眠很少是一个好主意(从这里的经验来看,是的,我已经这样做了,是的,我后来修复了这个问题),并且推测性能问题的根源也不是,特别是在多线程环境中。

Visual Studio 2010 beta1 有一个很棒的分析器,非常适合了解导致应用程序速度变慢的原因,Hazim Shafi 的博客介绍了如何使用它。

您还可以查看 Windows 性能工具包(您必须使用平台 sdk 安装程序,但您需要安装该节点,因此它实际上非常快)。

The first thing I would recommend doing is understanding what's causing the slowdown by profiling.

Throwing in random sleeps is rarely a good idea (speaking from experience here, yes I've done this and yes I've fixed this later) and neither is speculating on sources of performance problems particularly in a multi-threaded environment.

Visual Studio 2010 beta1 has a great profiler that is perfect for understanding what's causing the slowdowns if it's within your application, Hazim Shafi's blog walks through how to use it.

You can also look at the xperf tool which is available in the windows performance toolkit (you have to use the platform sdk installer, but you only need to install that node so it's actually pretty fast).

对你而言 2024-08-11 16:43:23

您是否尝试过在 XP 和 Windows 7 下运行相同的代码?

我有一些多线程代码可以渲染到屏幕外兼容的位图。每个线程渲染到它自己的兼容位图。然而,出于某种奇怪的原因,这张图在 vista 上花了很长时间。我将超过 50% 的处理时间浪费在 GDI 渲染上。在Win 7和XP下我没有这样的问题。有趣的是,我遇到了 这篇文章暗示 Vista 下的多线程 GDI 渲染已被彻底破坏。在某些时候,我会尝试提出一种方法,其中所有渲染都由我的主线程而不是辅助线程完成,以测试 Vista 性能是否有所提高。不过,这对编码来说将是一场巨大的噩梦,而且我的主要市场使用 XP,所以我不是;此刻闹腾的...

have you tried running the same code under XP and Windows 7?

I have some multithreaded code that renders to offscreen compatible bitmaps. Each thread renders to its own compatible bitmap. However for some odd reason this drawing takes AGES on vista. I lose over 50% of my processing time to the GDI rendering. Under Win 7 and XP I have no such problems. Interestingly I came across this article which implies that multithreaded GDI rendering under Vista is hopelessly broken. At some point I will try and come up with a method in which all rendering is done by my main thread instead of from ancillary threads to test out if Vista performance improves. This would be a huge nightmare of a thing to code though and my primary market uses XP so i'm not al; that fussed at the moment ...

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