The Sun, 21 Jun 2009 11:42:30 -0000, imacarthur <[email protected]>
wrote:
>
> 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.
>

    Thank you for your reply, I use threads usually without direct
interaction with the interface but in this case it seemed interesting to
inform the user on the progress of the download. I understand the need to
test this particular issue on all platforms.

>>
>>    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...
>
     I correct my program to always call show() before calling thread...

>>      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.
>

    It's a problem, i can't use "lock" on Windows OS in this thread, the
first "Fl::lock" freeze the thread ... and the GUI.
    Without this "lock" it works, i dedicated a popup window to this thread
and I hope to avoid conflicts.

>
>>        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