problems with multiple threads and XSync

Corbin Simpson mostawesomedude at
Tue Jul 20 07:27:28 PDT 2010

Just do XInitThreads once at the top of your program. Not that difficult.

Posting from a mobile, pardon my terseness. ~ C.

On Jul 20, 2010 12:53 AM, "Francesco Abbate" < at>

Hi all,

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:

XNextEvent(m_display, &m_event);

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

XSync(m_display, true);

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.

Best regards,
Francesco Abbate

PS: may be I can mention that on M$ Windoze the same kind of approach
is apparently working without any problem.
xorg at X.Org support
Your subscription address: mostawesomedude at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the xorg mailing list