--
You received this message because you are subscribed to the Google Groups "fltk.coredev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkcoredev...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/fltkcoredev/fc5cbd27-3152-4521-ad6d-40c03cf83b10n%40googlegroups.com.
I think the real rule is that you must call Fl::lock() in the main thread before any other thread calls it. You can run fltk single-threaded for as long as you want before this.
Similarly, in advanced.dox,The main() thread must call Fl::lock() once before any windows are shown, to enable the internal lock (it is "off" by default since it is not useful in single-threaded applications) but thereafter the main() thread lock is managed by the library internally.becomes
The main() thread must call Fl::lock() once before any thread is launched that may want to call Fl::lock/unlock, to enable the internal lock (it is "off" by default since it is not useful in single-threaded applications) but thereafter the main() thread lock is managed by the library internally.
RFC 1: I suggest that starting with FLTK 1.5, we add Fl::init_locking() which ensures that it is called from within the main thread. It would resolve the dual use of Fl::lock() (which could still keep its original functionality for back compatibility).
We could then also have Fl::deinit_locking(), but I doubt that that is ever really used.
RFC 2: in the rare case where a user wants to lock FLTK in the main thread, but outside of Fl::wait() or Fl::run(), we could document fl_lock_function() and fl_unlock_function(). Do we want to make that public?
I also suggest to update the comment for Fl::awake() to include the notion that Fl::lock() must have been called for Fl::awake() to work from within a thread:/**\brief Notifies the main GUI thread from a worker thread.In FLTK, worker threads can update the UI, but all UI changes must be wrappedbetween Fl::lock() and Fl::unlock(). After calling Fl::unlock(), the workerthread should call Fl::awake() to signal the main thread thatupdates are pending.It's \e not necessary to wrap calls to any form of Fl::awake() by Fl::lock()and Fl::unlock().
Nevertheless, the early, single call to Fl::lock() used toinitialize threading support is necessary.
Fl::awake() is typically called by worker threads, but it can be used safelyby the main thread too, as a means to break the event loop.\note Worker threads must not create, show, or hide windows.
RFC ...
RFC 1: I suggest that starting with FLTK 1.5, we add Fl::init_locking() which ensures that it is called from within the main thread. It would resolve the dual use of Fl::lock() (which could still keep its original functionality for back compatibility).
We could then also have Fl::deinit_locking(), but I doubt that that is ever really used.
RFC 2: in the rare case where a user wants to lock FLTK in the main thread, but outside of Fl::wait() or Fl::run(), we could document fl_lock_function() and fl_unlock_function(). Do we want to make that public?
I also suggest to update the comment for Fl::awake() to include the notion that Fl::lock() must have been called for Fl::awake() to work from within a thread:
/**\brief Notifies the main GUI thread from a worker thread.In FLTK, worker threads can update the UI, but all UI changes must be wrappedbetween Fl::lock() and Fl::unlock(). After calling Fl::unlock(), the workerthread should call Fl::awake() to signal the main thread thatupdates are pending.
It's \e not necessary to wrap calls to any form of Fl::awake() by Fl::lock()and Fl::unlock(). Nevertheless, the early, single call to Fl::lock() used toinitialize threading support is necessary.
Fl::awake() is typically called by worker threads, but it can be used safelyby the main thread too, as a means to break the event loop.\note Worker threads must not create, show, or hide windows.
src/Fl_cocoa.mm-526-void Fl_Cocoa_Screen_Driver::breakMacEventLoop()
src/Fl_cocoa.mm-527-{
src/Fl_cocoa.mm-528- NSEvent *event = [NSEvent otherEventWithType:NSEventTypeApplicationDefined
src/Fl_cocoa.mm-529- location:NSMakePoint(0,0)
src/Fl_cocoa.mm-530- modifierFlags:0 timestamp:0
src/Fl_cocoa.mm-531- windowNumber:0 context:NULL
src/Fl_cocoa.mm-532- subtype:FLTKBreakLoopEvent
src/Fl_cocoa.mm-533- data1:0
src/Fl_cocoa.mm-534- data2:0];
src/Fl_cocoa.mm-535- [NSApp postEvent:event atStart:NO];
src/Fl_cocoa.mm-536-}
... which is indeed called inside macOS specific DND handling and
maybe more, but very likely not by user code because it's not a
public (documented) function.Le vendredi 13 mars 2026 à 11:09:19 UTC+1, melcher....@googlemail.com a écrit :
Nevertheless, the early, single call to Fl::lock() used toinitialize threading support is necessary.
This sentence seems confusing to me because it mentions something to do once inthe main thread while discussing things to do in worker threads. I suggest to eitherremove it or place it at the end of the Fl::awake() description and with explicitmention it's for the main thread:The early, single call to Fl::lock() by the main thread used toinitialize threading support is necessary before worker threads begin using Fl::awake().