Re:Blocking code is a leaky abstraction
by koito17 on Saturday October 19, 2024 @09:55PM
(#41892306)
I agree with your comment. Every UI framework I have used (AppKit, Swing, JavaFX, etc.) is not thread-safe. It requires all UI code in the main thread or, in the case of JavaFX, a dedicated UI thread (not necessarily the main thread, but it must be a single thread where all UI operations occur).
WPF was the same IIRC
Re:Blocking code is a leaky abstraction
by solarkraft on Sunday October 20, 2024 @03:35PM
(#41897903)
yup!
That's how winforms did it; and I suspect that's how the underlying Windows OS needs it done too.
Re:Blocking code is a leaky abstraction
by mike_hearn on Sunday October 20, 2024 @12:33PM
(#41896531)
Technically in JavaFX you can work with UI objects off the main thread, for instance to load or build up UI in parallel. The single thread requirement only kicks in when UI is attached to a live window (stage).
IBM made a similar decision before the larger Java community thought it was anything like a good idea.
Even outside of UI, use-from-one-thread-only is perfectly valid and acceptable. The issue at that point is with the tools (e.g. C), not the API. If the API provides thread-safe entry points, that's because it is taking on the responsibility of synchronizing. Maybe that's fine for a particular API, but it shouldn't be expected for everything. It's an added layer of complexity, hidden from the programmer, so expect it to be absent in more optimized cases.
Uhm, every OS that I've developed a GUI for has a similar limitation. The "only call this thing from this thread" is a well-known thread safety pattern. It might not be the pattern that this author prefers, but it is an industry standard pattern for UI.