Re: threads and trayicon error



On Tue, 30 Sep 2008 00:25:01 +0200
anguila <anguila gmail com> wrote:

I attach the full code of 2 scripts.

David.

Yeah, those are helpful, but I can't run them. They are full of computer
specific directories,images, and GladeXML files. It would be nice if you could simplify
the problem down to a simple set of scripts, that anyone can run.
I don't feel like taking an hour to chop your script down to the bare thread guts.

But anyways.......
Your AppletcvNews.pl seems to be the only script starting threads.
A quick glance at it seems troublesome.

You start 1 thread with sub retard, and from that thread, you launch
other threads with the update_ico subs.
You seem to be letting a thread spawn other threads..... it's bound to be troublesome.

In Perl, when threads get spawned, they get an exact copy of the launcher at the time
of spawning. So when you deeply nest spawning threads, you are getting alot of the
parent's previous state getting copied into the new thread. Gtk2 has some thread safety,
but that is asking too much of it to track.

Some general rules for threads.

1. Try to launch the thread before any gui code is called. Maybe move 
threads->new("retard")->detach(); 
to the very top of your script, before any Gtk2 code is used. That will
keep the Gtk2 objects from getting copied.
That may be all you need.

2. Try to start the threads in update_ico at the top of your script too.
You can control them thru shared variables. Try to start all threads from the main parent
before any gui code is invoked.

3. If you need to modify widgets from a thread, call  GLib::Idle->add() in the thread.

sub thread_code{
  my $widget = shift;

   Glib::Idle->add(                                                         
                   sub{                                                                   
                     #modify $widget here
                    return FALSE;                                                         
                   });            
}

4. Instead of detaching, try to reuse threads, by refilling them with new data,
and join them when exiting. This will avoid pseudo-memory gains in your program,
as detached threads in GUI programs rarely completely clean up after themselves,
( ref_count dosn't go to 0), and they lay around in limbo causing havoc with your gui code. 


Other than that, try to devise a simple example that we can run.....no special directories, images,
or XML files, just simple Perl and threads

zentara


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



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