Hello,I am working on a multithreaded application with a FLTK GUI.On MacOS, certain changes to widgets can only be made from the main thread (changes to the menu bar for example), not from worker threads. When I see the need for such a change from within a worker thread I can signal the main thread with a Fl::awake(handler,void*) call. However, in my case this occurs in functions that may both be called from the main thread as well as from worker threads. I could of course figure out what thread I am in and either call Fl::awake or do the change to the menu directly, but is it possible to call Fl::awake also from the main thread? (Just to keep things more simple.)
As an alternative, could I use Fl::add_timeout with a very small delay time? As far as I can see there is no problem in adding a timeout from a worker thread, or is there?
--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/c5589888-207d-7b13-3d14-ba97c8472a6e%40online.de.
I would say that if FL::awake does not work from the main thread, it is a bug.I would fix this in whatever way uses the smallest amount of code. So first check if what it is doing already works (quite likely). If not, detect the main thread and call the callback directly before FL::awake returns.
Op maandag 24 oktober 2022 om 17:20:53 UTC+1 schreef spitzak:I would say that if FL::awake does not work from the main thread, it is a bug.
I just checked if Fl::awake(handler, xxx) works from the main thread and it seems it does. If as Bill says this should be working, will it then be an official feature so that I can start using it? Maybe that should then also be included in the manual?
I am indeed using FLTK 1.4 because I need some of the latest changes. As Ian points out, the manual says that one should avoid calling timers from working threads, but it does not mention that this has changed in version 1.4 (page 139 of the FLTK 1.4.0 Programming manual). Maybe this should be updated? I readily admit that the manual is sometimes (not always ;)) wasted on me, but at least in this case I learnt something new.
I just checked if Fl::awake(handler, xxx) works from the main thread and it seems it does. If as Bill says this should be working, will it then be an official feature so that I can start using it? Maybe that should then also be included in the manual?
True that detecting the main thread is not a problem (especially with std::this_thread::get_id() which should work on all platforms) but I have the impression that I am getting a lot of intermediate functions to handle this kind of stuff, so just calling Fl::awake and let FLTK do it would help a little in refactoring.
On Tuesday, 25 October 2022 at 09:16:53 UTC+1 geert karman wrote:
I am indeed using FLTK 1.4 because I need some of the latest changes. As Ian points out, the manual says that one should avoid calling timers from working threads, but it does not mention that this has changed in version 1.4 (page 139 of the FLTK 1.4.0 Programming manual).
Maybe this should be updated? I readily admit that the manual is sometimes (not always ;)) wasted on me, but at least in this case I learnt something new.
I'm not keen on changing the manual for this, at least not at this stage, as it would break potential portability.
As things stands, code "written for" 1.4 can generally be compiled and run just fine with 1.3 too, but if folks write code that depends on starting/stopping timers from a worker thread, that will certainly not be "backwards compatible", and might get a bit "crashy"...
Geert, could you please give more context of the text where you found this? I don't see this on "page 139" (note that the PDF version numbers can change from version to version, if that's what you meant with "page 139". I searched the docs for "timeout" (not "timer") but didn't find anything related to what you said.
Geert, could you please give more context of the text where you found this? I don't see this on "page 139" (note that the PDF version numbers can change from version to version, if that's what you meant with "page 139". I searched the docs for "timeout" (not "timer") but didn't find anything related to what you said.
One of the bullet points in section 14.5, "FLTK multithreaded Constraints" where it simply says: "Don't start or cancel timers from a worker thread".
I really appreciate it to have the possibility to call Fl::awake from the main thread as a property of FLTK 1.4. Thanks a lot!