Re: Threads with GTK

Daniel Adler <> writes:

> Elliot Lee wrote:
> > 
> > On Sun, 9 Aug 1998, Daniel Adler wrote:
> > 
> > > i have some problems with using gtk efficient with threads... i heard
> > > about the gpk-proxy but it does'nt hold a lot of gtk-wrappers i need to,
> > > especially because i'm coding threads in components (gtk-widgets).
> > >
> > > up to now, i use to communicate between the main-gtk-thread and my
> > > little working threads through idle_functions, but i think this is not
> > > efficient.
> > >
> > > does anyone knows, how to signal the main-gtk-thread that the datas are
> > > loaded (e.g. reading directory especially over ftp-links it's better not
> > > to lockup the display :) ) by the read_dir_thread, so that the
> > > main-gtk-thread can fill all the datas in clist.
> > 
> > You might want to investigate thread programming a bit more. Mutexes are a
> > fairly basic concept :)
> > 
> > > and is there anythink planned to make gtk thread-safe or will this be
> > > the gpk?
> > 
> > gtk+ 1.1.x includes a "I want to do gtk+ stuff" mutex, which makes it
> > easier to use from different threads.
> Does this mean, i only have to create a mutex, and if the
> second/third... thread want to call
> gtk stuff, it has to obtain the mutex-lock ? are there any special
> routines in gtk 1.1 
> (i use it at the moment for development) for global locking all
> gtk-routines, or do i have
> to lock/unlock the mutex each time in my main gtk-thread ?

GTK+-1.1 has:

 gboolean      gdk_threads_init  (void);
 void          gdk_threads_enter (void);
 void          gdk_threads_leave (void);

The first must be called before entering the main loop, and
before making any calls to other second two calls. It returns
TRUE if the copy of GTK+ was compiled with --enable-debug.

Then call gdk_threads_enter() before making GTK+ calls,
and gdk_threads_leave() when you are done. There is
(currently) no provision to automatically lock on all
entry points to GTK+, but the above isn't that onerous,
since one tends to make GTK+ calls in bunches.


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