News for hackers. Stuff that matters.
Re:Blocking code is a leaky abstraction by gwbas1c on Saturday October 19, 2024 @09:03PM (#41892074)
> Dependency Dog: If you want to see a good example of a leaky abstraction, consider AppKit. Not only is AppKit thread-unsafe to the point where many functions can only safely be called on the main() thread, it forces you into Apple’s terrifying Objective-C model. Basically any program that wants to have working GUI on macOS now needs to interface in Apple’s way, with basically no alternatives.

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.

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).
Re:Blocking code is a leaky abstraction by etcd on Sunday October 20, 2024 @02:40AM (#41893407)
WPF was the same IIRC
Re:Blocking code is a leaky abstraction by solarkraft on Sunday October 20, 2024 @03:35PM (#41897903)
yup!
Re:Blocking code is a leaky abstraction by gwbas1c on Monday October 21, 2024 @11:41AM (#41905352)
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).
Re:Blocking code is a leaky abstraction by hinkley on Sunday October 20, 2024 @11:28PM (#41900425)
IBM made a similar decision before the larger Java community thought it was anything like a good idea.
Re:Blocking code is a leaky abstraction by vacuity on Monday October 21, 2024 @03:30PM (#41907578)
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.