[cairo] [PATCH 2/2] xlib: Call XSync() before ignoring errors

Adam Jackson ajax at redhat.com
Tue Mar 7 20:28:30 UTC 2017


On Tue, 2017-03-07 at 11:39 +0100, Uli Schlachter wrote:

> Even better: XSetErrorHandler() has no Display* argument. This sets a
> global variable! This code is not even thread-safe and it cannot be.
> Hopefully, no one uses multiple Displays in a single program...

Yes, it's a terrible API.

A more idiomatic approach to this kind of problem is something like:

XLockDisplay(dpy);
next = NextRequest(dpy);
// still not thread safe but can at least check the exact request
bar = XSetErrorHandler(foo);
XShmGetImage(...);
XSetErrorHandler(bar);
XUnlockDisplay(dpy);

Failing that, if you _really_ want to be correct here, there is also a
real async API in Xlib. It's not what you might call documented, and
it's moderately painful to use, but it's ABI (some extension libs rely
on it) and per-display so you don't have the thread safety problem.

- ajax


More information about the cairo mailing list