ARC
ARC

Reputation: 1804

Why is UI drawn on main thread?

Is there a reason why all the UIKit drawing or AppKit drawing is done on main thread ?

Upvotes: 2

Views: 385

Answers (3)

bmitc
bmitc

Reputation: 853

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.

Upvotes: 0

bbum
bbum

Reputation: 162722

"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.

Upvotes: 2

Omar Abdelhafith
Omar Abdelhafith

Reputation: 21221

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?

Upvotes: 5

Related Questions