On 20 Jun 2009, at 14:11, [email protected] wrote:
>
>     I wish you soummettre a small problem in the use of threads under
>     Linux and Windows, a slightly different behavior.
>     Fltk 1.1.9 , linux Mandriva and Windows XP (Cygwin)

If the issues you are seeing are to do with different behaviour with  
regard to (for example) calling show() from a child thread, and so  
on, then I would say that even on linux, different window managers  
can behave differently, so the fact that it worked in your set-up  
might not be a robust indication that it will work in general.

The whole multi-threading GUI context thing is tricky... to say the  
least.

To make your code as portable as possible, try and keep as much of  
the GUI stuff in the primary main() thread, and only have the child  
threads access the GUI context directly when absolutely necessary.
What is allowed on one OS and WM combination might be quite different  
from another so keeping it localised to the main thread makes the  
code more portable.

>
>    function mythread() {
>      ...
>      popup->show();


I would advise against calling show() from a child thread, I don't  
think you can count on that working cross-platform reliably.

>      ...
>      while(1) { // recv packets
>        ...
>        Fl::lock();
>        popup->set(stats); // transfert progress
>        Fl::unlock();
>        Fl::awake();
>        ...
>      }
>      ...
>    }
>
>    Under Windows I managed to get this same result, noting that the  
> use of
> "Fl::lock" ... lock the thread, and that the popup-> show() does not
> appear if it
> called in the thread
>
>    function mycallback() {
>      ...
>      popup->show();

This is probably a better place to call show() in general...

>      call thread()
>    }
>
>    function mythread() {
>      ...
>      ...
>      while(1) { // recv packets
>        ...

I assume there is an Fl::lock() here but you have not shown it.

>        popup->set(stats); // transfert progress

I assume there is an Fl::unlock() here but you have not shown it.


>        Fl::awake();
>        ...
>      }
>      ...
>    }
>
>    It works but I would like to know if this is a good solution.

With the lock/unlock added, the second way looks about right to me.



_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to