Is there a reason why all the UIKit drawing or AppKit drawing is done on main thread ?
-
possible duplicate of [Why are most UI frameworks single threaded?](http://stackoverflow.com/questions/5544447/why-are-most-ui-frameworks-single-threaded) – jscs Jun 08 '12 at 18:01
3 Answers
This is the main pattern of all GUI drawing to be done on a single thread, Accessing the screen for adding element and drawing is not a multithreaded process
Imagine a case where you have 10 threads, each of them tries to draw and or move elements on the screen, that would create un deterministic errors and issues that would be very difficult to handle and/or to find
Also read more here Why are most UI frameworks single threaded?

- 1
- 1

- 21,163
- 5
- 52
- 56
-
1+1: simple answer that hits the spot. You actually could manage UI from several threads but things could very easily get out of hands. – Rok Jarc Jun 08 '12 at 11:49
-
You could implement GUI drawing in a multithreaded way, but I expect that by the time you have added locking to stop two threads from trying to draw the same thing at the same time or different things in the same place at the same time, you will have lost all the advantages at the expense of adding locking overhead and nasty indeterminate bugs. – JeremyP Jun 08 '12 at 12:23
"Because multithreaded drawing quickly becomes too complex/confusing" is only half the answer.
The other major impediment to multithreaded UI management is event handling. Mixing processing of events into concurrent drawing, specifically. You would have to somehow intermingle drawing with the chaos that is a monkey bashing on screen/keyboard/mouse while effectively maintaing a notion of transactional integrity.
Already, this is hard without concurrency.

- 162,346
- 23
- 271
- 359
Out of the desktop operating systems, macOS' Cocoa window system is the only one that requires windows to be created and managed on the application's main thread, that is, the thread that the program starts on. X11 on Linux and Win32 on Windows requires window creation and management to be on a single thread, but it can be any thread.
GUI frameworks don't need to be single-threaded. The only requirement is that window management is on a single thread, and on macOS, that thread has to be the main thread.

- 357
- 1
- 9