Qt 文档说,
As mentioned, each program has one thread when it is started. This thread is called the "main thread" (also known as the "GUI thread" in Qt applications). The Qt GUI must run in this thread.
Android 文档说,
Like activities and the other components, services run in the main thread of the application process
和 iOS,
It is strongly recommended not to update UI controls etc from a background thread (e.g. a timer, comms etc). This can be the cause of crashes which are sometimes very hard to identify. Instead use these to force code to be executed on the UI thread (which is always the “main” thread).
为什么他们使用单线程模型来更新 UI?
最佳答案
简短的回答是,这是确保显示不损坏的唯一合理方法。
长话短说,允许多个线程更新 UI 会导致死锁、竞争条件和各种麻烦。这是 Java 的 AWT(以及其他 UI 系统)允许多个线程访问 UI 的惨痛教训。参见,例如,Multithreaded toolkits: A failed dream? .该帖子(通过无效链接)指的是Why Threads Are A Bad Idea和 Threadaches .
关于android - 为什么使用单线程模型作为主线程来更新 UI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11772658/