Hi everyone, I am working on a multi-threaded application. The thing is, it working perfectly for a while, but after that it fall into a deadlock.
Here is the code layout: // Thread function // It is signaled to wake up for every 1 second gpointer motion_compile_thread(gpointer data) { ... while (TRUE) { if (!g_mutex_trylock(cp_mutex)) continue; g_cond_wait(compile_cv, cp_mutex); .... .... g_mutex_unlock(mutex); gdk_threads_enter(); // do somethin do_refresh(xxxx) gdk_threads_leave(); } void do_refresh(void) { if (!g_mutex_trylock(cp_mutex)) continue; // do something, but guarantee won't cause recursive call to do_refresh g_mutex_unlock(cp_mutex); } The program worked without problem for a while(about 5 minute) but after that it hangs. Here is the gdb backtrace. (gdb) bt #0 0xb7fe1424 in __kernel_vsyscall () #1 0xb74c9e82 in __lll_lock_wait () from /lib/libpthread.so.0 #2 0xb74c535b in _L_lock_505 () from /lib/libpthread.so.0 #3 0xb74c5181 in pthread_mutex_lock () from /lib/libpthread.so.0 #4 0xb79475b6 in ?? () from /usr/lib/libgdk-x11-2.0.so.0 #5 0xb7985e3e in ?? () from /usr/lib/libgdk-x11-2.0.so.0 #6 0xb7515096 in g_main_context_prepare () from /usr/lib/libglib-2.0.so.0 #7 0xb7515f33 in ?? () from /usr/lib/libglib-2.0.so.0 #8 0xb7516a1b in g_main_loop_run () from /usr/lib/libglib-2.0.so.0 #9 0xb7af95b9 in gtk_main () from /usr/lib/libgtk-x11-2.0.so.0 #10 0x080536b3 in gui_main (builder=0x80e0828) at gui/gui-main.c:185 #11 0x08052e15 in main (argc=1, argv=0xbffff1e4) at main.c:127 (gdb) thread 2 [Switching to thread 2 (Thread 0xb322cb70 (LWP 24441))]#0 0xb7fe1424 in __kernel_vsyscall () (gdb) bt #0 0xb7fe1424 in __kernel_vsyscall () #1 0xb74c9e82 in __lll_lock_wait () from /lib/libpthread.so.0 #2 0xb74c535b in _L_lock_505 () from /lib/libpthread.so.0 #3 0xb74c5181 in pthread_mutex_lock () from /lib/libpthread.so.0 #4 0xb79475b6 in ?? () from /usr/lib/libgdk-x11-2.0.so.0 #5 0xb7947b80 in gdk_threads_enter () from /usr/lib/libgdk-x11-2.0.so.0 #6 0x0805b676 in motion_compile_thread (data=0x8117330) at motion.c:96 #7 0xb753ebcf in ?? () from /usr/lib/libglib-2.0.so.0 #8 0xb74c2df0 in start_thread () from /lib/libpthread.so.0 #9 0xb743f98e in clone () from /lib/libc.so.6 >From what I can see, the program is stuck because the main thread locked a mutex in #3. But from the backtrace, the mutex seems to be locked by gtk_main_loop_run() which is something I can't control, and somehow it locked the same mutex as gdk_threads_enter()? any ideas? Thanks, Wei-Ning Huang _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list