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

Adam Jackson <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
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
-- 
cairo mailing list
[email protected]
https://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.