Re: Threads breaking either Perl's or Gtk2's internals



On Mon, 24 Mar 2008 14:47:05 +0100
David KubÃÄek <dave awk cz> wrote:

Hello,

I'm having problems with threads in my GTK application. You can see exactly what I'm doing from the attached 
files. Both were originally a testing script I found here when browsing archives, so please ignore 
formatting, etc - they're not mine. :) I

Hi, I get the same results as you running your scripts. I have 2 examples to show you.

The first, is almost like yours, and the thing you will notice, is how you need to turn off
thread safety (with explanation by muppet), AND you need to use timers and Idle->add
to manipulate the $pbar from the thread. 

Threads can be very tricky. If you want foolproof thread operation, you need to make
reusable(I call them sleeping threads). I have one in the second example below.
In the third example, I control 3 sleeping threads.
These all run well, and you might want to adapt the sleeping thread model. It is possible
that you may be able to spawn threads dynamically, and destroy(detach) them when done,
but almost every attempt to do that (which I've seen) fails with errors after a few invocations.

So, threads can be used safely, but at the current state of development, you need
to reuse threads and control them thru shared variables. Don't try to make "disposible
detached threads". They may seem to work, but you will often get a memory gain for
each thread, and they fail eventually with repeated calls.

GoodLuck, remember to use Timeouts instead of sleep, and use Glib::Idle->add() from
your thread code block to manipulate widgets in the main thread.

zentara


-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html

Attachment: thread2a
Description: Binary data

Attachment: thread-idle-add3
Description: Binary data

Attachment: zz-gtkthreads-z-w-multi-indicator0
Description: Binary data



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]