GNOME Bugzilla – Bug 155038
Bug when using gdk_threads_enter and gdk_threads_leave
Last modified: 2004-12-22 21:47:04 UTC
Please describe the problem: When i use these functions the application freeze and after no actions are possible. On Linux it works well but on Windows there is this problem. Steps to reproduce: 1. 2. 3. Actual results: Expected results: Does this happen every time? On windows yes this happen every time Other information: An exemple to show you the problème try it on Windows with Visual or DevC++. It shows a dialog box which is created in another thread : #include <stdlib.h> #include <gtk/gtk.h> #include <windows.h> /* Dialog message */ void msg(GtkWidget *window){ GtkWidget *dialog; gdk_flush(); gdk_threads_enter(); dialog = gtk_message_dialog_new (GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "OK"); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); gdk_threads_leave(); } /* test thread */ void *test(void *data){ /* Do something ... */ /* Shows final info */ msg(data); return(NULL); } /* test callback */ void test_callback(GtkButton *button, GtkWidget *window){ g_thread_create(test, window, FALSE, NULL); } /* window with 2 buttons */ GtkWidget *create_window(){ GtkWidget *window, *button1, *button2, *hbuttonbox; window = gtk_window_new(GTK_WINDOW_TOPLEVEL); g_signal_connect(GTK_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), window); hbuttonbox = gtk_hbutton_box_new(); gtk_widget_show(hbuttonbox); gtk_container_add (GTK_CONTAINER (window), hbuttonbox); button1 = gtk_button_new_from_stock ("gtk-quit"); gtk_widget_show (button1); gtk_container_add (GTK_CONTAINER (hbuttonbox), button1); g_signal_connect(GTK_OBJECT(button1), "clicked", G_CALLBACK(gtk_main_quit), NULL); button2 = gtk_button_new_with_label("test"); gtk_widget_show(button2); gtk_container_add(GTK_CONTAINER(hbuttonbox), button2); g_signal_connect(GTK_OBJECT(button2), "clicked", G_CALLBACK(test_callback), window); return(window); } int main(int argc, char **argv){ GtkWidget *window; /* Inicia o gtk*/ g_thread_init(NULL); gdk_threads_init(); gtk_init (&argc, &argv); window = create_window(); gtk_widget_show(window); gdk_threads_enter(); gtk_main (); gdk_threads_leave(); return 0; }
GTK on Windows doesn't work if used from multiple threads.
*** This bug has been marked as a duplicate of 60620 ***