Re: gtk app with threads




"Cristóvão B. B. Dalla Costa" said:
Problem is, the idle thread doesn't ever get called. I'm creating it as
such:

    Glib->idle_add (sub { $self->update_progress (\$downloaded) });

Where $downloaded is a shared variable.

I hope you mean Glib::Idle->add(), not Glib->idle_add().  Also, you're taking
a new reference to $downloaded, which i don't think is what you mean.

I wager your idle handler is actually running once, then uninstalling itself,
since returning nothing is interpreted as returning FALSE.  You have to return
TRUE from a source's callback to keep the handler installed.

Also, an idle will probably run *far* more often than is necessary.  Use a
timeout with a delay of about 200ms, e.g.

   Glib::Timeout->add (200, sub {
           $self->update_progress ($downloaded);
           # return FALSE when finished, TRUE until
           ($downloaded < 1.0)
   });


Does anyone here have experience with this type of problem? How would
you recommend solving this particular design problem?

I'd look at Gnome2::VFS, which uses worker threads for async downloads, and
even has an example program which does pretty much what it sounds like you're
trying to do.


-- 
muppet <scott at asofyet dot org>



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