[Xcb] [PATCH 3/3] fix pthread_cond_wait and get_socket_back dependency

Jamey Sharp jamey at minilop.net
Wed Jun 5 14:38:02 PDT 2013


On Thu, May 16, 2013 at 11:35:07AM +0200, Christian König wrote:
> Am 16.05.2013 02:02, schrieb Jamey Sharp:
> >Consider, for example: What happens if xcb_take_socket is called from
> >two threads at once?
> 
> Not much, changing socket ownership is protected by the iolock. So
> when two threads call into xcb_take_socket the thread who can
> acquire the iolock wins and gets the socket. The other thread gets
> the iolock after the first returns from xcb_take_socket and so calls
> return_socket to get the socket back to xcb before giving it out
> again.
> 
> But that's exactly the argument why the current implementation
> doesn't work correctly, any caller of xcb_take_socket must make sure
> that the socket isn't stolen by another thread. The conventional way
> to do so is to use a locking primitive, which is acquired by the
> caller of xcb_take_socket and inside return_socket.

Multiple libraries are intended to be able to share XCB's socket. For
instance, I might build an application using Xlib, cairo, and a
higher-level language binding to XCB that does its own request
marshalling.

Xlib uses its Display lock to prevent other threads from calling
xcb_take_socket from inside Xlib, but that doesn't stop another thread
from calling xcb_take_socket from cairo, or from the language binding.

I believe those cases are OK, though, because if (for instance) Xlib
gets the socket, then when cairo tries to take it, XCB will call Xlib's
return_socket, and that will block on Xlib's Display lock until Xlib is
done using the socket.

However, getting back to this patch: If there's a bug of the sort you're
trying to fix here, then if Xlib's running xcb_take_socket on one
thread, and cairo is running it on another, I expect that bug will
apply.

Therefore, I think either there is not a bug here, or this patch isn't
complete--and since I can't prove to myself that the patch is correct, I
can't tell which.

Jamey
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.freedesktop.org/archives/xcb/attachments/20130605/dd4ab034/attachment.pgp>


More information about the Xcb mailing list