On 30 Aug 2012, at 17:59, Bogdan Popescu wrote:

> I'm not that good with threads... I gave it a go under Linux and it seems
> to work fine for the first time it renders the window, after the second or
> third try it might segfault (when calling Fl_Window::show() or Fl::run())
> and you cannot close the window opened by FLTK, also the window is redrawn
> when a new message is received instead of spawning a new one... I'm
> thinking the way FLTK works with threads is different, right now I have all
> my FLTK code under the last called function, do you think I need to/should
> initialize fltk in main() and then spawn windows from the running threads?


No, that isn't going to work - threading is not a drop-in for forking the 
process, on any platform; in particular many host systems will only permit the 
primary "main" thread to create new windows in a GUI context so you can not 
make new windows from the subsidiary threads.

I guess this is analogous in some ways to the OSX fork behaviour where the 
subsidiary fork can't create windows - though there at least the "fix" is easy 
in that you can exec a new process in place of the child, and the new process 
can create windows. There is no easily managed way to do that from threads...

So you *can* probably use threads to attain your goal, but it will require a 
fair amount of re-working of your code I suspect.

> 
> Right now I replaced the fork calls with pthread (adding the
> pthread_detach/join calls where needed), and stick Fl::lock/unlock in the
> function that deals with FLTK...

Hmm, very unlikely to work - see notes above, and refer to the "Advanced" 
section of the fltk manual (used to be Chapter 10 in the old fltk-1.1 docs...)

> 
> I assume there must be a way of dealing with this without going for the
> agent approach but thank you for your replies!

For linux and OSX, the fork/exec way should work. For WinXX, you will probably 
need to consider the agent approach anyway, so that might be the path of least 
resistance overall?




_______________________________________________
fltk mailing list
fltk@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to