problems with multiple threads and XSync

Corbin Simpson mostawesomedude at gmail.com
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" <francesco.bbt at gmail.com>
wrote:

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:

...
my_application_unlock();
XNextEvent(m_display, &m_event);
my_application_lock();
...

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
thread:

my_application_lock();
XPutImage(...);
XSync(m_display, true);
my_application_unlock();

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 lists.freedesktop.org: X.Org support
Archives: http://lists.freedesktop.org/archives/xorg
Info: http://lists.freedesktop.org/mailman/listinfo/xorg
Your subscription address: mostawesomedude at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.x.org/archives/xorg/attachments/20100720/828da410/attachment.html>


More information about the xorg mailing list