Re: drawing area won't refresh on X11 unless touched, app ismultithreaded, gtk 2.0



Hello,

I had a similar problem in my application.

First, gtk_thread_init bombs if you link in the
incorrect library with gtk 2.0.  Make sure you use:
pkg-config --libs gthread-2.0    or
$(shell pkg-config --libs gthread-2.0) for gmake
when linking your application.

This was it, I was linking to glib12.

Second, I would add the following prior to calling
gtkmain():

if(!g_thread_supported()) {
    g_thread_init(NULL);
    gdk_threads_init(); }
else ????

OK.

gdk_threads_enter();
gtk_main();
gdk_threads_leave();

Well I am doing this:

pthread_create(&gtk_main_thread,NULL,gtk_main,NULL);

But I would be cautious about wrapping gtk_main with those calls because
wouldn't that make the event loop starve everyone else out like Xiong Huan
says in his post?

gtk is not thread safe, so any time you call the gtk
api, you have a critical section. So.

while(1) {
    sleep(1);
    gdk_threads_enter();
    x = (gdouble)((double)random()/
        RAND_MAX)*drawing_area->allocation.width;
    y = (gdouble)((double)random()/
        RAND_MAX)*drawing_area->allocation.height;
    draw_brush(drawing_area,x,y);
    gdk_threads_leave();
 }

OK.

Hope this helps.

Immensely, it now works without a hitch, thanks for your time.

trigonometric




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