X display locking

Aaron Plattner aplattner at nvidia.com
Thu Mar 7 08:48:22 PST 2013


On 03/07/2013 06:31 AM, Torsten Jager wrote:
> Hello!
>
> What is the proper usage of XLockDisplay () / XUnlockDisplay ()
> when an application has multiple threads using
>
>    * "normal" Xlib functions
>    * Xitk functions
>    * libGL and/or
>    * libvdpau ?

XLockDisplay / XUnlockDisplay is only required when you need multiple 
requests to be atomic with respect to requests being sent by other 
threads.  For example, if you have a function like

XGrabServer()
XGetImage()
XUngrabServer()

then you'll probably want to bracket the whole thing with XLockDisplay / 
XUnlockDisplay if you have another thread that could otherwise perform 
rendering during the grab or destroy the window you're trying to 
GetImage or something.

> On my machine (libX11 1.4.0) bracketing all 4 seems to be necessary
> to avoid lockups and stack corruption. At least doing so does
> work here.

You shouldn't get lockups unless you take the lock in one thread and 
don't release it.  You did call XInitThreads() as the very first thing, 
right?

> Hovever, on my mate's box the same code traps both libGL and
> libvdepau into an infinite sched_yield () polling loop.

Sounds like a bug.

> What am I doing wrong?

My guess would be calling XInitThreads too late.  You have to call it 
before anything else, including libraries like libGL and libvdpau, make 
any Xlib calls.

> Torsten

-- 
Aaron


More information about the xorg mailing list