XDrawPoint(s) etc MT safe?
Adam Jackson
ajax at nwnk.net
Wed Oct 17 15:09:32 UTC 2018
On Tue, 2018-10-16 at 22:04 -0400, Dennis Clarke wrote:
> On 10/16/2018 09:58 PM, Dennis Clarke wrote:
> > Dear Xorg :
> >
> > Something I had not thought of came up today. Could multiple threads
> > call XDrawPoint() and then XFlush() ? Suppose sixteen threads are
> > dispatched to do some foo and each of them utters some XDrawPoint()
> > calls and then XFlush()? Is that remotely thread safe?
> >
>
> Sorry, assume XInitThreads() is in place. Am I stuck with using
> XLockDisplay() and XUnlockDisplay() and really multiple threads can
> not really do work simultaneously. That is the question.
Individual Xlib function calls are thread-safe, in that they internally
lock the Display while they're running to avoid multiple threads
modifying the Display state. Note how the first thing XDrawPoint does
is call LockDisplay:
https://gitlab.freedesktop.org/xorg/lib/libx11/blob/master/src/DrPoint.c#L36
So if you had two threads calling XDrawPoint in parallel, the second
one would block at that LockDisplay until the first one was done.
You only need XLockDisplay() if you're trying to establish an atomic
sequence of actions with respect to your sibling threads. For example,
if one thread was doing XQueryTree in a loop, and another was creating
and destroying windows, you could end up with a sequence like:
Thread A creates window 1
Thread B queries for the root window's children, learns window 1
Thread A destroys window 1
Thread B queries for window 1's children, gets BadWindow
- ajax
More information about the xorg
mailing list