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

Re: Multithreaded applications and GTK+




> I'm developing a multi-threaded application with GTK+. Each thread is
> supposed to have a state, and they should show it in a clist, using
> gtk_clist_set_text. In the FAQS I have read that the correct way is to
> prepend gdk_threads_enter(); and append gdk_threads_leave(); to every
> gdk-related statement, to lock and unlock the mutex of GDK, so
> everything works. But this seems too hard and too messy. Isn't there any
> smarter way of doing it? Or have I understood the docs badly?

i'm not sure what you mean by too hard since it's just some extra typing
to do.  you could write a macro to eliminate some of it:
#define THREAD(a) (gdk_threads_enter(), (a), gdk_threads_leave())
and then you could do things like:
THREAD(gtk_clist_append(GTK_CLIST(clist), data));

the problem with this is that it will surround all gtk statements with
gdk_threads_enter() and gdk_threads_leave() and you may want to run
several without locking and unlocking the mutex around each one of them.

alternately, you could use IPC to communicate with one drawing thread, but
this is probably going to be more complicated than surrounding gtk calls
with gdk_threads_enter() and gdk_threads_leave()



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