Re: Problem with GUI not (always) updating...



On Mon, 2007-04-02 at 19:35 +0200, Matthias Scheer wrote:
> Michael L Torrie schrieb:
> > This is classic behavior when you use threads in GTK without following
> > the instructions for using GTK in a threaded way. 
> > 
> > Does your thread interact with the gui at all?  Are you following the
> > documentation for setting up GDK threading and locking any calls to gtk
> > from your thread?  If you are calling gtk calls from your thread for the
> > purpose of updating the gui, consider calling the thread-safe g_idle_add
> > call from your thread and then having a callback (which would run in the
> > main GUI thread) do any gui calls for you.
> 
> Actually, I am only updating the GUI right before I send the worker 
> threads to sleep, mainly to save CPU time for the computation. I've been 
> trying to fix this behavior with a pthread mutex that locks on GUI 
> access but after reading the FAQ I think this only made it worse.

No need to use pthread mutexes for this particular thing.  The Gtk
threading apis already provides general lock calls to protect stuff.
You need to initialize threading in GTK (GDK actually) and then surround
gtk or gdk calls with the _enter and _leave calls.  See:

http://www.gtk.org/faq/#AEN482

the g_idle_add method is the more portable, and easier to work-with
solution in many cases.  Since you are using threads, you still will
want to initialize the threading system with a call to g_thread_init and
gdk_threads_init.

> 
> Thanks for the heads-up and sorry for asking FAQ-material.

no worries.  

> 
> Matthias Scheer
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list




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