Hi,

I have seen a few posts saying its bad/illegal to do GUI calls from threads 
other than main (where the widgets were created).

A few weeks ago I inherited some code that uses FLTK 1.1.7 and does exactly 
that.  I'm running on an ARM under linux.

Besides main, there are a couple other threads that call show, hide, and label. 
 Probably others too, but those are the most common.

It is a mostly working product but there are a few of outstanding problems:

- widgets that don't get redrawn unless another cycle of hide() and show() is 
called.

- occasional garbage label text (that is also fixed with a hide/show cycle).

- a seemingly random segmentation fault that (from gdb's stack trace) always 
comes from malloc.  I've started using environment variable MALLOC_CHECK_=2 
which causes malloc to do heap consistency checks but that didn't buy me much 
-- its still in a malloc call which presumably is sometime after the actual 
damage is done.  The only trace I have captured in this scenario was during the 
font loading which appears to be in a non-main thread.  That's what got me 
thinking about thread safety, and this posting.

Program terminated with signal 6, Aborted.
#0  0x40171c40 in kill () from /lib/libc.so.0
#1  0x4001701c in pthread_kill () from /lib/libpthread.so.0
#2  0x400175d0 in raise () from /lib/libpthread.so.0
#3  0x4016be44 in abort () from /lib/libc.so.0
#4  0x4016e380 in __malloc_consolidate () from /lib/libc.so.0
#5  0x4016d5f8 in malloc () from /lib/libc.so.0
#6  0x4004ea98 in XQueryFont (dpy=0x180588, font_ID=0) at QueryFont.c:58
#7  0x4004e8c8 in XLoadQueryFont (dpy=0x180588, name=0x9cac4 "fixed")
    at QueryFont.c:8
#8  0x00082614 in Fl_FontSize::Fl_FontSize ()
#9  0x000828a8 in fl_font ()
#10 0x40025600 in __pthread_manager_thread () from /lib/libpthread.so.0
Backtrace stopped: frame did not save the PC
(gdb)

Today I put a mutex in each customized widget (and subclassed Fl_Window and 
Fl_Box too, for this purpose) so I could ensure that the widget modifiers were 
not happening at the same time as draw() calls.  I don't have that protection 
totally in place yet.  But then I saw Lock() and Unlock() and am wondering if 
those will do the same thing.  And then I saw the forum posts that made me 
think:

Do I need to re-architect the whole thing?

Any comments would be appreciated.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to