为什么大多数 UI 框架都是单线程的? [英] Why are most UI frameworks single threaded?

查看:31
本文介绍了为什么大多数 UI 框架都是单线程的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,Java Swing 和 Android UI 都使用单线程模型,其中一个 UI 线程负责更新所有 UI.是什么让框架设计者选择了一种线程模型而不是另一种?

For example, Java Swing and Android UI both use a single threaded model where a single UI thread is responsible for updating all the UI. What made the framework designers chose one thread model over the other?

多线程 UI 模型不会以更高的复杂性为代价为您提供更高的性能吗?我意识到后者很重要,因为与线程相关的错误令人讨厌,但我想知道单线程模型除了简单之外是否还有其他优势?

Wouldn't multiple threaded UI model potentially give you more performance albeit at the cost of more complexity? I realize that the latter is a big deal because thread related bugs are nasty but I am wondering if there are any other advantages to single-threaded model other than simplicity?

推荐答案

是什么让框架设计者选择了一种线程模型而不是另一种?

What made the framework designers chose one thread model over the other?

来自马口:

AWT 最初被暴露为正常多线程 Java 库.但作为Java 团队查看了经验与 AWT 和死锁和人们遇到过的种族,我们开始意识到我们正在做一个我们无法兑现的承诺.

AWT was initially exposed as a normal multi-threaded Java library. But as the Java team looked at the experience with AWT and with the deadlocks and races that people had encountered, we began to realize that we were making a promise we couldn't keep.

这种分析最终导致了1997 年 Swing 的设计评论,当时我们回顾了 AWT 的比赛状态,以及整体的行业经验,我们接受了 Swing 团队的建议 Swing 应该只支持非常有限多线程.

This analysis culminated in one of the design reviews for Swing in 1997, when we reviewed the state of play in AWT, and the overall industry experience, and we accepted the Swing team's recommendation that Swing should support only very limited multi-threading.

(阅读整篇文章,它非常详细地解释了该决定,并指出完全相同的问题和最终转向单线程模型的问题甚至更早在施乐 PARC 发生过——几乎所有我们认为的现代前沿技术都在这里发生CS 是 30 年前发明的)

(Read the whole article, it explains the decision in great detail and states that the exact same problems and eventual move to a single-threaded model had even occured earlier at Xerox PARC - the place where almost everything we consider bleeding edge modern in CS was invented 30 years ago)

不会是多线程的 UI 模型可能会给你更多的表现尽管以增加复杂性为代价?

Wouldn't multiple threaded UI model potentially give you more performance albeit at the cost of more complexity?

绝对不会,因为绘制 GUI 和处理用户操作(这是 UI 线程需要做的一切)不会成为任何健全的 2D 应用程序的瓶颈.

Absolutely not, because drawing the GUI and processing user actions (which is everything the UI thread needs to do) is not going to be the bottleneck in any sane 2D application.

这篇关于为什么大多数 UI 框架都是单线程的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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