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.

-- 
Cyrus Patel - cyrus linuxfan com
Dept. of Computer Engineering                             Debian GNU/Linux 
University of New South Wales                             (Woody)
Sydney, Australia.                                        ICQ: 50738541 
http://www.cyrusp.com  Mobile: +61 0402 266 731 cyrusmobile linuxfreak com






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