多线程WinApp:主线程瓶颈 [英] Multi-threaded WinApp: main thread bottleneck

查看:114
本文介绍了多线程WinApp:主线程瓶颈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个利用多个线程的游戏引擎.在当前状态下,它使用两个线程:一个用于处理Windows消息(主线程),另一个用于OpenGL.

它不是紧迫的问题,但是我发现主线程瓶颈在OpenGL线程上.这意味着,如果主线程的更新循环比另一个循环花费更长的时间完成,它将减慢它的速度.如果主线程较慢,则GL线程将仅以与主线程相同的速度更新.

显然,这并不是主要问题,因为主线程再也没有比OpenGL线程更多的工作了,但是我想知道发生了什么,以便更好地了解Windows上的winapi和OpenGL.

有人知道这里发生了什么吗?

注意:每当我与窗口交互(移动,调整大小等)时,GL线程都会正常更新.

I''m creating a game engine that utilizes multiple threads. In its current state, it uses two threads: one for handling windows messages (main thread), and another specifically for OpenGL.

Its not of immediate concern, but I have discovered that the main thread bottlenecks the OpenGL thread. What this means is that if the update loop of the main thread takes longer to complete than loop in the other, it will slow it down. If the main thread is slower, the GL thread will only update as fast as the main thread.

Obviously this isn''t a major issue since the main thread will never have more to do than the OpenGL thread, but I''d like to know whats going on to better understand the winapi and OpenGL on windows.

Does anyone know whats happening here?

Note: The GL thread will update normally whenever I interact with the window (move it, resize it, etc).

推荐答案

在您的情况下,有两件事会影响时间共享
1)线程优先级
2)如果线程由于等待共享资源而被阻塞(例如,关键部分)

如果您的OpenGL线程具有比主线程更高的优先级,并且没有阻塞情况,那么您的主线程就不可能放慢OpenGL线程的速度.
In your situation, 2 things affect time sharing
1) Thread priorities
2) If thread(s) is/are blocked due to waiting for a shared resource (a critical section for example)

If your OpenGL thread has a higher priority than the main thread, AND there are no blocking situations, it is not possible for your main thread to slow down your OpenGL thread.


再多一点经过实验,我解决了这个问题.

我正在通过将其显示在窗口标题中来监视来自GL线程的帧速率.

当我停止显示帧率时,很明显GL线程不再受到main的影响.

我得出的结论是,SetWindowText()必须经过Windows消息传递系统后才能完成执行. GL线程在处理该消息之前无法继续,因此将其性能与主线程的性能相关联.

感谢收到的帮助,希望这篇文章对其他人有帮助.
After a little more experimentation I solved the issue.

I was monitoring the frame rate coming from the GL thread by displaying it in the window''s title.

When I stopped displaying the frame rate it was clear that the GL thread was no longer being affected by the main.

What I have concluded is that SetWindowText() must not finish execution until it has passed through the windows messaging system. the GL thread could not continue until that message was processed and thus linked its performance to that of the main thread.

I appreciate the help I received and hopefully this post will helpful to others.


这篇关于多线程WinApp:主线程瓶颈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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