为什么大程序(如游戏)不使用不同线程的负载? [英] Why don't large programs (such as games) use loads of different threads?

查看:158
本文介绍了为什么大程序(如游戏)不使用不同线程的负载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道商业游戏如何在内部工作,但我所遇到的开源游戏似乎没有大规模的线程。对于大多数其他桌面应用程序也是如此,通常会使用两个或三个线程(例如程序逻辑和GUI更新)。

I don't know how commercial games work inside very much, but the open source games I have come across don't seem to be massively into threading. Same goes for most other desktop applications, normally two or three threads seem to be used (eg program logic and GUI updates).

为什么游戏没有很多线程?

Why don't games have many threads? Eg separate threads for physics, sound, graphics, AI etc?

推荐答案

现在许多游戏都使用任务或工作系统并行处理。也就是说,游戏产生用于多个任务的固定数量的工作线程。工作分成小块并排队,然后发送以便在工作线程可用时进行处理。

Many games these days are using "task" or "job" systems for parallel processing. That is, the game spawns a fixed number of worker threads which are used for multiple tasks. Work is divided up into small pieces and queued, then sent to be processed by the worker threads as they become available.

这在控制台上变得特别常见。 PS3基于Cell架构,因此您需要使用并行处理来获得系统的最佳性能。 Xbox 360可以模拟为PS3设计的任务/作业设置,因为它有多个内核。你可能会发现,对于大多数游戏,许多系统设计在360,PS3和PC代码库中共享,所以PC很可能使用同样的策略。

This is becoming especially common on consoles. The PS3 is based on Cell architecture so you need to use parallel processing to get the best performance out of the system. The Xbox 360 can emulate a task/job setup that was designed for PS3 as it has multiple cores. You would probably find for most games that a lot of the system design is shared among the 360, PS3, and PC codebases, so PC most likely uses the same sort of tactic.

    虽然很难编写线程安全的代码,很多其他的答案表明,我认为有几个其他的原因。
  • 首先,许多开源游戏都是几年前。特别是对于这一代控制台,并行编程正变得普及,甚至如上所述是必要的。

  • 第二,很少有开源项目似乎关注获得最高的性能。由于约翰·卡马克指出了犹他州GLX项目,高度优化的代码通常比未优化的代码更难维护,所以后者通常在开源环境中更受欢迎。

  • 第三,不要使用由游戏创建的少量线程,这意味着它不能很好地使用并行作业。

  • First, many open source games are a few years old. Especially with this generation of consoles parallel programming is becoming popular and even necessary as mentioned above.
  • Second, very few open source projects seem concerned about getting the highest possible performance. As John Carmack pointed out to the Utah GLX project, highly optimized code is often harder to maintain than unoptimized code, so the latter would generally be preferred in open source contexts.
  • Third, I wouldn't take a small number of threads created by a game to mean that it's not using parallel jobs well.

这篇关于为什么大程序(如游戏)不使用不同线程的负载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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