為什麼 GUI framework 大多都是 single-threaded (not thread safe)
主要原因為有兩個不同方向的 operation:GUI activity 跟 input event。 GUI activity 是由 UI 最上層 app code 一路到底層 OS, 而 input event 則是相反,從底層 OS 一路往上到 app code。 要用 lock 來保護不同方向的 operation 很難,很容易 deadlock, 所以比較省事的方法就是所有 GUI activity 都用一個 thread 處理 (一種 event driven 的概念), 這樣另一個方向的 input event 就能當成是一種「event」。 參考資料: Multithreaded toolkits: A failed dream? Why must/should UI frameworks be single threaded? Why are most UI frameworks single threaded? Why is a single threaded model used to update the UI as main thread? What does threadsafe mean?