[Glade-users] glade and thread-safe code...
Damon Chaplin
damon@helixcode.com
Tue, 14 Nov 2000 16:26:35 +0000
Roberto Diaz wrote:
>
> > GTK+ has a global lock which you must get with GDK_THREADS_ENTER
> > before calling any GTK+ code. (And release with GDK_THREADS_LEAVE.)
> > I think GLib is thread-safe - it handles any locking needed itself.
> > I think people normally keep all GUI code in one thread and use other
> > threads for background tasks etc.
>
> Yes but lets suppose I want to have a thread recieving remote data (which
> are just points) and draw these points in a drawing area...
>
> If I start protecting my code with the global lock:
>
> GDK_THREADS_ENTER..
>
> code which draws in a drawing area.. (is a loop)
>
> GDK_THREADS_LEAVE.
>
> since my thread is painting all the time (so for this I want it to be
> a thread).. it never release the global lock...
>
> What effect can have this in the main GUI thread? for example if a get an
> exposure event.. and I want to repaint some part.. will I need to have the
> lock?.. must I notify this to the "paint thread" and let it die (for
> example)?..
I'm no thread expert, but I'd suggest that you have 2 threads - one for
the display and one to manage the data. And you just lock the data as it
is passed from one thread to the other somehow, e.g. using a GList as a queue
of incoming points.
(I think I was wrong about GLib. It isn't completely thread-safe so you will
have to lock the GList yourself.)
Damon