Re: [fltk.general] Use worker thread to call Fl_Window and Fl_run

GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
Previous Message ]New Message | Reply ]Next Message ]

Re: Use worker thread to call Fl_Window and Fl_run Ian MacArthur 06:13 Oct 25 top right image
On 25 Oct 2020, at 11:24, anmol.mishra wrote:
> Could Ian and Greg kindly comment on main_gui_on_secondary.cpp ? This program uses fl_create_thread and the worker thread starts the progress window and calls Fl::run().
> In the docs this is forbidden. 
> >>
> Don't call Fl::run(), Fl::wait(), Fl::flush(), Fl::check() or any related methods that will handle system messages from a worker thread 
> >>
> Why is this working ? From my example, (no longer a progress bar but a more complex UI), I get a crash when the user closes the window if started from a worker thread.

I’d suggest that it is *not* working - though it may appear to be.

Further, I’d caution that even if it does “work" for you, it may well *not* work for other users, or even on different PC’s. 
By accessing the GUI context from the non-primary thread, you are at the mercy of the GPU and it’s related OS and driver layers, and how they maintain the context; and at that point you are out into the wilds (on your own...)

The crash on exit, at a guess, is most likely caused by something unwinding the GUI context and deleting widgets and related artefacts, but since it is in the “wrong" thread context it is deleting something in the wrong memory context and segfaulting...

That’s exactly the sort of thing that will happen, and why we advise against running the GUI from any non-primary thread.

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
To view this discussion on the web visit
Direct Link to Message ]
bottom left image   bottom right image
Previous Message ]New Message | Reply ]Next Message ]

Comments are owned by the poster. All other content is copyright 1998-2020 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to ''.