4 ms·
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 th
by koito17 2y ago
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).
- etcd 2y agoWPF was the same IIRC
- solarkraft 2y agoyup!
- gwbas1c 2y agoThat's how winforms did it; and I suspect that's how the underlying Windows OS needs it done too.
- mike_hearn 2y agoTechnically 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).
- hinkley 2y agoIBM made a similar decision before the larger Java community thought it was anything like a good idea.
- vacuity 2y agoEven 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.