FLTK logo

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

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   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 Sep 30, 2020  
 
On 30 Sep 2020, at 17:49, anmol.mishra wrote:
> 
> Hi. I want to create a simple progress bar, and do not need any user input. I cannot block my main app as it already has its own GUI.
> What will happen if I use the following from a worker thread ?



> I read the docs, and its clear that the main thread owns the window, but if I dont care about user input, is there any harm in this ?


It’s not about user input - the issue is what process, and what thread within that process, owns the context that writes to the GPU...

Now, with more modern GPU drivers, and operating systems, that’s not as fragile as it once was, but basically the *safe* thing to do is handle GUI context from the main thread, always.

Trying to create windows from a subsidiary thread is likely to lead to trouble in strange and hard to debug ways...

However, the key here is that you do not need to call Fl::run() at all, if you only want to drive the GUI from your main thread: all you have to do is call Fl::wait(0); every now and then (say every 100ms or so if you just want to update the GUI but not handle user input...)

So if you can create and show all the window objects in your main thread, then arrange for Fl::wait() to be called periodically from the main thread, that ought to just about do the job.




-- 
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/164D254C-807D-4A0E-B6A4-C1EFE7180043%40gmail.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

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