GTK deadlock in gtk_main
- From: "Tomas Soltys" <tomas soltys range-software com>
- To: gtk-app-devel-list gnome org
- Subject: GTK deadlock in gtk_main
- Date: Tue, 3 Aug 2010 22:15:47 +0200 (CEST)
Hi all,
I am not sure if this is a bug or just my misunderstanding of how the
synchronization is done in GTK.
Below is a simple "test.c" example in which the deadlock occurs.
Basically program deadlocks itself when "idle_func" is done and control is
returned to "gtk_main".
Thanks for your help in advance,
Tomas
====================================================================
#include <stdlib.h>
#include <glib.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
static GStaticMutex customMutex = G_STATIC_MUTEX_INIT;
static void custom_enter (void) {
g_print ("LOCK\n");
g_static_mutex_lock (&customMutex);
}
static void custom_leave (void) {
g_static_mutex_unlock (&customMutex);
g_print ("UNLOCK\n");
}
static gboolean on_delete_event (GtkWidget *widget,
GdkEvent *event,
gpointer user_data) {
gtk_widget_destroy (widget);
gtk_main_quit ();
return TRUE;
}
static gboolean idle_func (gpointer user_data) {
/* Do something */
g_print ("IDLE start\n");
gtk_main_iteration_do (FALSE);
g_print ("IDLE end\n");
return FALSE;
}
int main (int argc, char *argv[]) {
GtkWidget *window;
gdk_threads_set_lock_functions (custom_enter, custom_leave);
g_thread_init (NULL);
gdk_threads_init ();
gdk_threads_enter ();
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (G_OBJECT(window), "delete-event",
G_CALLBACK(on_delete_event),
NULL);
g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, idle_func, NULL, NULL);
gtk_widget_show (window);
gtk_main ();
gdk_threads_leave ();
return EXIT_SUCCESS;
}
====================================================================
compile command: gcc test.c -o gtkTest `pkg-config --cflags --libs gtk+-2.0`
LINUX dist.: Fedora 13
GTK version: 2.20.1
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]