problems with multiple threads and XSync
francesco.bbt at gmail.com
Tue Jul 20 00:52:37 PDT 2010
I've a problem with a multi threaded application were multiple threads
access to Xlib concurrently. In order to make things safe I've
implemented a lock mechanism but I still experiment some intermittent
(rare) problems with XSync that hang sometimes.
Let me explain how I have arranged the locks for the multiple threads.
There is a thread, lets say the main thread that poll the events and
process them as needed. In order to make things safer all the
operations are locked and the thread unlocks only during the blocking
event polling. So I have something like that:
The other thread, lets say the secondary thread, perform other stuff
not related to the Xlib but, in some cases it does need to force an
update on the Window. In order to perform this operation it does
acquire the lock (the same as the main thread of course) and perform
two operations: an XPutImage and an XSync with a "true" flag to
discards incoming events. So I have something like that for the second
The logic of this approach is that we let the secondary thread perform
the XPutImage, XSync operation only when the main thread is polling
events and is probably blocked anyway. This approach does not work and
sometimes the XSync hang I don't know why.
Should I use the XInitThread functions and the related locks to fix
the problems or I need to adopt some other approach ?
Any help or suggestions is highly appreciated. Thank you in any case.
PS: may be I can mention that on M$ Windoze the same kind of approach
is apparently working without any problem.
More information about the xorg