httpinterpret
httpinterpret

Reputation: 6709

Why the gtk windows hangs?

void forloop2()
{
    int i = 0;
    while(TRUE)
    {
        printf("forloop2\n");
    }
}

int main() {
    GtkWidget *window;
    g_thread_init(NULL);
    gdk_threads_init();
    g_thread_create((GThreadFunc)forloop2, NULL, FALSE, NULL);
    gtk_init(NULL, NULL);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_widget_show_all (window);
    gtk_main();
}

It seems the created thread affects gtk_window_new(my programe hangs here),

how do I do it correctly?

UPDATE

fixed by gdk_threads_enter/leave

Upvotes: 1

Views: 920

Answers (1)

nyxdis
nyxdis

Reputation: 417

From the GDK docs:

You must also surround any calls to GTK+ not made within a signal handler with a gdk_threads_enter()/gdk_threads_leave() pair.

See http://developer.gnome.org/gdk/stable/gdk-Threads.html#gdk-Threads.description

Upvotes: 1

Related Questions