XDrawPoint(s) etc MT safe?

Dennis Clarke dclarke at blastwave.org
Wed Oct 17 19:53:23 UTC 2018


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

Beauty. So I don't really need to call XLockDisplay or XUnlockDisplay
inside any given thread.  Looks redundant. That helps.

> So if you had two threads calling XDrawPoint in parallel, the second
> one would block at that LockDisplay until the first one was done.

Perfect ... thank you!

> 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

ah yes .. well I hope to never have a thread do anything like that.

Thank you.

Dennis






More information about the xorg mailing list