Re: multithreading



Dragos Boca <dboca@pcnet.ro> writes:

> If i have a multi-thread program how can I change properties of a widget
> from inside a thread ?

Normally, you should gtk_idle_add () a function that does the
change. This will make the change happen in GTK's mainloop, i.e., in
the "int main ()" thread. In general, don't try to use GTK from more
than one thread - it isn't worth the trouble. 

If for some reason, perhaps because you need to synchronize the widget
changes with whatever your thread does, you can't use gtk_idle_add(),
then reconsider your design. Threads might not be what you need - or
you may need a clearer separation between frontend (user interface)
and backend (what your program actually does).

If you still need to do do this, then make all of GTK a critical
region, that is, use gdk_threads_enter() and gdk_threads_leave()
around *all* code that uses GTK. This is likely to come back to bite
you, though.




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