Creating a widget from another thread

11 views
Skip to first unread message

pavlick

unread,
Jul 3, 2024, 1:10:14 PM (3 days ago) Jul 3
to fltk.general
Hi guys. I read the documentation which states:

"A worker thread may update the state of an existing widget, but it may not do any rendering directly, nor create or destroy a window"

But what is "window creation"? Is it widget constructor call (which is hided initially), or is it call of show() method which actually creates the window? Can i create a window in worker thread without show() call, pass this new window object to the main thread (insert it into some kind of widget pointer array), and main thread will call show() method of this new window?

If i can create widgets without show() from worker threads, should i call Fl::lock() before the constructor call?

imm

unread,
Jul 3, 2024, 1:31:29 PM (3 days ago) Jul 3
to General FLTK
I would not, I'd be concerned that the resulting behaviour may be inconsistent across platforms.

I'd use the Fl:: awake () callback mechanism to construct the window (and to show/hide it too, if and when necessary.)

The callback scheme is generally a "better" approach than using the lock too, in general, as it allows concurrency more readily.

There's some discussion of this in the "Advanced" section of the docs.
--
Ian
From my Fairphone FP3
   

message  you are  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/c4b0ce47-7a6b-4c7f-a916-4ce3ecb46b34n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages