Re: gtk and multithreading



WOW!!!  Finally I see some commonality with my work :)

I have a GUI that actually uses about 5 threads for each node in the system, in addition to the main thread.

We found that we had to use the folowing code in each thread (specifically the GDK_THREADS_ENTER/LEAVE stuff) in order for the threads to not get in each others' way:

    if (rCode == ERR_SUCCESS)
    {
       sprintf(loadbuf, "%s", rate);
       GDK_THREADS_ENTER();
       gtk_label_set_text(GTK_LABEL(sys_load_label),loadbuf);
       GDK_THREADS_LEAVE();
     }

We also had the problem with the update not showing on the display until the mouse was moved, but fixed that by "invalidating" the section of the display that we were affecting. our problem happened primarily when trying to display pixmap widgets...though I think the problem essentially has to do with latency in the windows - specifically how the windows/widgets get repainted only when the application gets to so idle time...

In any case, this code fixed the display latency, but left us with some flickering issues...which we resolved by coding around it *sigh* and displaying only when absolutely necessary (wow...forced into good coding style - who woulda thunk?):

 if(widget->window)
   gdk_window_clear_area_e(widget->window, widget->allocation.x,
                         widget->allocation.y, widget->allocation.width,
                         widget->allocation.height);

It's entirely possible that there are other ways to fix this, since I too, am a relative newbie at this GUI stuff...but this worked for us.

Paul

Brad House wrote:

I've got a problem.

The main program I have calls gtk_main() and everything works great until I get into threads.

What I'm trying to do is call a thread to connect to a remote
server. And when it recieves a response, it needs to pop up a window showing the response.

Well anyhow it works for the most part...I'm using libglade
so I'm doing a gtk_widget_show(widget);  where the widget has
already been referenced and hidden, etc.  But the use of
libglade should be most irrelevant.

the only problem is that the widget won't display until I move
the mouse...

if I use gtk_widget_show_now(widget) instead it gives me an error
about the main loop running in another thread, but again it displays
properly as soon as I move the mouse.

The only solution I can think of is to emit an event of some sort, and
have the main loop capture the event and show the window for me instead
of having my thread do it, but this is my first attempt at creating any
GUI ... ever ... anywhere. So, the whole event structure is new to me (but I seem to have everything else besides threads down!)

Also, I looked at the example in the FAQ, and it IS showing a redraw
of a text field. So it seems as though a thread can update the GUI, so this really confuses me...maybe I'm not using the gdk_enter_thread()
stuff properly....

Any help would be much appreciated...thank you.

-----------------------------
Brad House
Sr. Developer
Main Street Softworks, Inc.

brad mainstreetsoftworks com
(352) 378-8228
-----------------------------

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