Thread programming



I'm new to thread programming, but necessity calls for threads in the
application I'm writing, so I've started learning how to use them.

The main problem I'm running into now is that when a looping thread
tries to update a label in the GUI, the main thread seems to lock up. 
I'm sure I'm missing something basic, probably need to lock something. 
But basically, here is what I'm doing:

// main.c 
...
g_thread_init(NULL);
...
pthread_create(&check_tid, NULL, check_queues, window1);
... 
gdk_threads_enter();
gtk_main ();
gdk_threads_leave();


// check_queues.c
    while (1) {
        ...(check some mysql database for data)...
        gdk_threads_enter();
        label = lookup_widget(GTK_WIDGET(toplevel),"label_name");
        gtk_label_set_text(GTK_LABEL(label), "whatever");
        gdk_threads_leave();
    }


The GUI responds normally until the second cycle of the above
check_queues function.  When the label is set the second time, the GUI
locks up.

I've read the FAQ on thread programming, but I must be missing something
fundamental on how they work.

Any help is greatly appreciated.

-- 
Justin Hopper <gus gusalmighty com>




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