How do I make child thread exit when main thread exit?

Posted by httpinterpret on Stack Overflow See other posts from Stack Overflow or by httpinterpret
Published on 2010-05-09T13:14:57Z Indexed on 2010/05/09 13:18 UTC
Read the original article Hit count: 147

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

int main() {
    GThread          *Thread1;
    GtkWidget *window;
    g_thread_init(NULL);
    gdk_threads_init();
    gdk_threads_enter ();
    Thread1 = g_thread_create((GThreadFunc)forloop2, NULL, TRUE, NULL);
    gtk_init(NULL, NULL);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_widget_show_all (window);
    gtk_main();
    g_thread_join(Thread1);
    gdk_threads_leave ();
}

When I close the window, how to make Thread1 also exit?

© Stack Overflow or respective owner

Related posts about c

    Related posts about gtk