Hi all, Please consider the attached C source. It runs fine on FreeBSD, but freezes on Linux. gtk_dialog_run() calls a recursive main loop, but I don't know how to interpret this fact to solve my problem. The workaround I use actually is to simply remove the gdk_threads_enter()/gdk_threads_leave() pair wrapping the main loop, as the program runs fine without them. Why should I wrap the main loop with that pair? Is the attached program not correct? Did I mess up somewhere? Best regards, Jean-Yves Lefort -- Jean-Yves Lefort jylefort brutele be http://void.adminz.be/
#include <gtk/gtk.h>
/* compilation: */
/* cc `pkg-config --cflags --libs gthread-2.0 gtk+-2.0` -o gtk2-threadbug gtk2-threadbug.c */
static gboolean delete_event_handler (GtkWidget *widget,
GdkEvent *event,
gpointer user_data);
int main (int argc, char **argv)
{
GtkWidget *window;
GtkWidget *dialog;
g_thread_init (NULL);
gdk_threads_init();
gtk_init (&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_show (window);
g_signal_connect(G_OBJECT(window), "delete_event",
G_CALLBACK(delete_event_handler), NULL);
dialog = gtk_message_dialog_new(GTK_WINDOW(window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_WARNING,
GTK_BUTTONS_OK,
"Test dialog");
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
/* on Linux the next instruction will freeze, on FreeBSD it will run fine */
gdk_threads_enter();
gtk_main();
gdk_threads_leave();
return 0;
}
static gboolean delete_event_handler (GtkWidget *widget,
GdkEvent *event,
gpointer user_data)
{
gtk_main_quit();
return TRUE;
}
Attachment:
pgpiOChWZhkIx.pgp
Description: PGP signature