GDK Threads, gtk_main_iteration, and freeze



Hi.

Many applications use the following loop:

/* START */

while (gtk_events_pending())
   gtk_main_iteration();

/* END */

This loop is also there in Gaim. But this started causing problems when
gdk_threads_init() was introduced to the code. The problem is: when this
loop is executed while a mouse-dragging is in action, the whole application
freezes. Following is a backtrace after causing a coredump with SIGABRT:

(gdb) bt
#0  0xffffe410 in __kernel_vsyscall ()
#1  0xb75d956e in __lll_mutex_lock_wait () from
/lib/tls/i686/cmov/libpthread.so.0
#2  0xb75d60c0 in _L_mutex_lock_29 () from
/lib/tls/i686/cmov/libpthread.so.0
#3  0xbfd29118 in ?? ()
#4  0xb78ce9d1 in IA__g_free (mem=0xb75d956e) at gmem.c:187
#5  0xb7b79dfc in gdk_threads_impl_lock () at gdk.c:377
#6  0xb7bad477 in gdk_event_prepare (source=0xfffffffc, timeout=0xfffffffc)
at gdkevents-x11.c:2274
#7  0xb78c953c in IA__g_main_context_prepare (context=0x8110908,
priority=0xbfd291d8) at gmain.c:2362
#8  0xb78c9bec in g_main_context_iterate (context=0x8110908, block=1,
dispatch=1, self=0x80e0558) at gmain.c:2655
#9  0xb78ca317 in IA__g_main_loop_run (loop=0x83125e8) at gmain.c:2879
#10 0xb7d3ea31 in IA__gtk_main () at gtkmain.c:999
#11 0x080a553a in main (argc=3, argv=0xbfd2b444) at gtkmain.c:781
(gdb)

However, when this loop is excuted any other time, everything works well.

I am going to try to explain with the following code:

/* START */

void abc()
{
   ...
   while (gtk_events_pending())
       gtk_main_iteration();
   ...
}

void normal()
{
   ...
   abc();
   ...
}

void mousedrag()
{
   ...
   gdk_threads_enter();
   abc();
   gdk_threads_leave();
   ...
}

int main()
{
   ...
   if (!g_thread_supported())
       g_thread_init(NULL);
   gdk_threads_init();
   gtk_init_check(&argc, &argv);
   ...
   gtk_main();
   ...
}

/* END */

"abc" is the function with the said loop, "normal" is a function which calls
"abc" when the mouse is not dragging, and things work. "mousedrag" is the
function which is executed while the mouse is being dragged. Without
gdk_threads_enter and gdk_threads_leave in "mousedrag", the application
freezes when it reaches the mainloop after returning from "mousedrag".

For more information, the actual file is
http://svn.sourceforge.net/viewvc/gaim/trunk/src/gtkblist.c?view=markup, and
the proposed patch is http://sourceforge.net/support/tracker.php?aid=1541864

I have noticed similar use of gdk_threads_enter and _leave in other
applications (eg. gnome-xine). Can someone explain what is going on?

A similar problem has been reported earlier:
http://mail.gnome.org/archives/gtk-app-devel-list/2005-February/msg00162.html

Regards,
Sadrul



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