RE: App doesn't quit



It seems the main loop is *asleep* until gdk get an events (?)

Anyway, it works with gtk_exit(0), in place of gtk_main_quit.

Example using it with gthread below (so it compiles under win32 too :D)
(
BTW, GURUS, is it the RIGHT WAY (or not so bad) to use gthread ?????
Thanks in advance
)

Ciao

Hugues

____

/* threads.c */

#include <gtk/gtk.h>

void BgTask(void *p)
{
    gulong i;
        g_print("Background task -one- started\n");
        while (TRUE) {
    for (i = 0; i < 20000000; i++);
        g_print("Background task -one- looping again\n");
        }
}

void BgTask2(void *p)
{
    gulong i;
        g_print("Background task -two- started\n");
    for (i = 0; i < 200000000; i++);
        g_print("Background task -two- finished\nQuiting\n");
    gtk_exit(0);
}


int CreateBgTask(void)
{
    if (!g_thread_create(&BgTask, NULL, 1024/*not sure of this*/, FALSE,
FALSE, G_THREAD_PRIORITY_LOW) != 0) {
        g_print("Cannot create background task\n");
        return -1;
    }
        if (!g_thread_create(&BgTask2, NULL, 1024, FALSE, FALSE,
G_THREAD_PRIORITY_LOW) != 0) {
        g_print("Cannot create background task\n");
        return -1;
    }
    return 0;
}

gint deleteCb(GtkWidget *widget, GdkEvent *event, gpointer data)
{
    gtk_main_quit();
    return FALSE;
}

gint destroyCb(GtkWidget *widget, GdkEvent *event, gpointer data)
{
    gtk_main_quit();
    return 0;
}

int main(int argc, char *argv[])
{
    GtkWidget *win;

    gtk_init(&argc, &argv);
        if (!g_thread_supported())
                g_thread_init (NULL);


    win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_signal_connect(GTK_OBJECT(win), "delete_event",
GTK_SIGNAL_FUNC(deleteCb), NULL);
    gtk_signal_connect(GTK_OBJECT(win), "destroy",
GTK_SIGNAL_FUNC(destroyCb), NULL);
    gtk_widget_show(win);

    CreateBgTask();

    gtk_main();

    return 0;
}
/* end of file */





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]