trouble with terminating pthreads in GTK



Hi,

I am writing a GTK app which plots some graph from realtime data.

When the start button is pressed in this app, it creats two threads, one
is for reading the input and one is for drawing the graph.

pthread_create(&input_pid, NULL, read_input, NULL);
pthread_create(&draw_pid, NULL, draw_thread, NULL);

The drawing thread looks something similar to this:

void *draw_thread(void *arg)
{
    pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
    while (terminate_cond==FALSE) {
        /* some code here to wait for a drawing signal
         * to update the graph
         */
         pthread_mutex_lock(blah...)
         pthread_cond_wait(blah...)
         pthread_mutex_unlock(blah...)

         /* !!! Sometimes, this thread failed to terminate
          * and hangs here
          */
         gdk_threads_enter();
         draw();    /* all the drawing code go in this function */
         gdk_threads_leave();
    }
}

However, I am having some trouble to terminate this drawing thread when
the stop button is pressed. I use this to terminate the drawing thread;
    pthread_cancel(draw_thread);

I guess this is a deadlock situation between the drawing thread and the
GTK's main thread, but I don't know how to resolve this. Your help would
be much appreciated.

Please cc me with the reply. I am not on both lists.

Regards,

Shao.
-- 
____________________________________________________________________________
Shao Zhang - Running Debian 2.1  ___ _               _____
Department of Communications    / __| |_  __ _ ___  |_  / |_  __ _ _ _  __ _ 
University of New South Wales   \__ \ ' \/ _` / _ \  / /| ' \/ _` | ' \/ _` |
Sydney, Australia               |___/_||_\__,_\___/ /___|_||_\__,_|_||_\__, |
Email: shao cia com au                                                  |___/ 
_____________________________________________________________________________




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