Vincent Nuttin <[email protected]> writes:
>
> 2011/4/11 Vincent Nuttin <[email protected]>:
> > Hi,
> >
> > I'm currently developing some kind of personal "plugin" for tangogps
> > (for my Openmoko FreeRunner running SHR).
> > My plugin uses a socket to receive information thus, I need to run
> > this part in an other thread (because I need an infinite loop for
> > checking for new messages on the socket).
> > Then, upon receiving a new message, I just want to "repaint_all()" ...
> > but, I got an X error:
> > "tangogps: Fatal IO error 11 (Resource temporarily unavailable) on X
> > server :0.0."
>
> I solved the problem with a "magic" call to g_timeout_add() ;-)
Yes: basically the GUI toolkit is not threadsafe (accessing it from
multiple threads simultaneously will often result in catastrophe),
and g_timeout_add() puts a function in a queue so that it's called from
the main thread--safely *interleaved* with all of the other normal
GUI operations.
On unix platforms at least, it is also actually safe to perform
GUI operations from auxiliary threads *if* you acquire the GDK mutext
with gdk_threads_enter() (and release it, when done, with
gdk_threads_leave()): this will enforce strict separation/ordering
of GUI operations even when they occur in separate threads.
There's an entry about this in the GTK+ FAQ:
http://developer.gnome.org/gtk-faq/stable/x481.html
And there's also some interesting discussion in the GNOME Live! wiki
(from 2008, but I believe it's all still relevant):
http://live.gnome.org/GdkLock
--
"Don't be afraid to ask (λf.((λx.xx) (λr.f(rr))))."
_______________________________________________
Shr-devel mailing list
[email protected]
http://lists.shr-project.org/mailman/listinfo/shr-devel