Re: trouble with terminating pthreads in GTK



I'm experciencing the same problems. In fact, when using the GCond's , the
code deadlocks here and doesn't even start drawing. Unfortunaly no solution
yet...

Jeroen

On Fri, 20 Oct 2000 08:34:53 Cyrus Patel wrote:
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



_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list







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