On Fri, 30 Oct 2026 20:37:14 +0100, Jeroen Belleman wrote:
> That's where threads are useful: The GUI is one thread, and the
> "other things" are in one or more other threads. There are
> altogether too many programs that hang the GUI while "other things"
> are going on. That should never happen!
Back in the 1990s, threading was seen as the answer to everything.
Some even tried multithreaded GUIs.
The trouble with threading is its “default-shared-everything” model,
as opposed to separate processes, which are “default-shared-nothing”.
It is all too easy to forget to synchronize access to shared objects,
lock things properly etc, and end up with hard-to-diagnose bugs that
tend to hide themselves when you try to go look for them (see
“Heisenbug”).
The trend nowadays is to revive the old coroutine concept, in a new
guise called “stackless” coroutines. These give you support for async
operations, but with transfers of control being made explicit at
“await” points, rather than unpredictably as with full preemptive
threading. This greatly reduces the opportunity for race conditions.
Credit to Microsoft for pioneering this, but nowadays you see the idea
popping up in JavaScript and Python and who knows where else.
Threading is still definitely useful, mainly for performance, where
the bottleneck is in CPU usage. But if a program is spending most of
its time waiting for I/O over the network, or for a user to initiate a
GUI action, or something external and relatively slow like that, then
coroutines keep things simpler.