[转]Ogre1.7的多线程分析
http://blog.csdn.net/butwang/article/details/6219424
在OgreConfig.h文件中有关于Ogre使用多线程的配置
1. 多线程支持的级别
OGRE_THREAD_SUPPORT = 0
No support for threading.
OGRE_THREAD_SUPPORT = 1
Thread support for background loading, by both loading and constructing resources
in a background thread. Resource management and SharedPtr handling becomes
thread-safe, and resources may be completely loaded in the background.
The places where threading is available are clearly
marked, you should assume state is NOT thread safe unless otherwise
stated in relation to this flag.
OGRE_THREAD_SUPPORT = 2
Thread support for background resource preparation. This means that resource
data can streamed into memory in the background, but the final resource
construction (including RenderSystem dependencies) is still done in the primary
thread. Has a lower synchronisation primitive overhead than full threading
while still allowing the major blocking aspects of resource management (I/O)
to be done in the background.
*/
#ifndef OGRE_THREAD_SUPPORT
#define OGRE_THREAD_SUPPORT 0
#endif
#if OGRE_THREAD_SUPPORT!= 0 && OGRE_THREAD_SUPPORT!= 1 && OGRE_THREAD_SUPPORT!= 2
#define OGRE_THREAD_SUPPORT 0
#endif
2.支持多线程库的thread lib来源
/** Provider for threading functionality, there are 4 options.
OGRE_THREAD_PROVIDER = 0
No support for threading.
OGRE_THREAD_PROVIDER = 1
Boost libraries provide threading functionality.
OGRE_THREAD_PROVIDER = 2
Poco libraries provide threading functionality.
OGRE_THREAD_PROVIDER = 3
TBB library provides threading functionality.
*/
#ifndefOGRE_THREAD_PROVIDER
#define OGRE_THREAD_PROVIDER 0
#endif
2.1 一个是boost提供的线程库
2.2 一个是Poco libraries
POCO C++ Libraries 提供一套 C++ 的类库用以开发基于网络的可移植的应用程序,功能涉及线程、线程同步、文件系统访问、流操作、共享库和类加载、套接字以及网络协议包括:HTTP、FTP、SMTP 等;其本身还包含一个 HTTP 服务器,提供 XML 的解析和 SQL 数据库的访问接口。
http://www.google.com.hk/search?hl=zh-CN&source=hp&biw=1241&bih=575&q=Poco+libraries&aq=f&aqi=&aql=&oq=
2.3 TBB library
http://threadingbuildingblocks.org/
Intel® Threading Building Blocks (Intel TBB) offers a rich and complete approach to expressing parallelism in a C++ program. It is a library that helps you take advantage of multi-core processor performance without having to be a threading expert. Intel TBB is not just a threads-replacement library. It represents a higher-level, task-based parallelism that abstracts platform details and threading mechanisms for scalability and performance.
3.Ogre多线程的初始化
在OgreMain中搜索OGRE_THREAD_SUPPORT得出以下文件清单
3.1分析OgreRoot.cpp中有关OGRE_THREAD_SUPPORT的代码:
Ogre 1.7 的 Threading changes
- WorkQueue added to accept generalised work items to be executed in background worker threads
- WorkQueue starts the number of workers based on hardware, or can be told to start a different number
- Main Ogre WorkQueue is in Root::getWorkQueue. You can also subclass WorkQueue and provide your own if you want
- ResourceBackgroundQueue now uses WorkQueue instead of using its own queue and can have multiple tasks running at once
- New focus on data-driven, task-based parallel execution with separation of GPU and CPU activities
- Boost, POCO and Thread Building Blocks supported as threading back-ends (Boost preferred)
- All Ogre thread support will use WorkQueue in future
备注:1.7添加了一个Character Sample,其中SinbadCharacterController有参考价值。
采用OGRE_THREAD_SUPPORT = 1并不被推荐,而应该使用OGRE_THREAD_SUPPORT = 2。sinbad在Using the new threading scheme说明了原因。更具体的讨论在high performance thread support - request for comments。当前,有Proposal: OGRE_THREAD_SUPPORT == 3,但是没有整合到Ogre 1.7中。
关于多线程参考:多线程的渲染与物理模拟(pdf)和Threading the OGRE3DRender System(pdf)
2010/07/07刷新:关于WorkQueue可以参考OGRE多线程的使用
PS. 在用CMake编译Ogre时,通过以下两个选项配置Ogre对多线程的支持:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构