[Xcb] Xlib/XCB in multi-threaded situation results in deadlock

Jamey Sharp jamey at minilop.net
Mon Mar 14 18:19:53 PDT 2011


On Thu, Dec 02, 2010 at 12:13:17AM +0200, Rami Ylimäki wrote:
> > > It seems that the drawing thread is suck on the poll and waiting for a
> > > reply, while the input thread is actually reading data from the socket.
> > > This causes the above deadlock.

Assuming this application uses only Xlib, and doesn't do event handling
using XCB directly, the bug is almost certainly the one big current Xlib
threading bug. I'm now tracking that bug here:

https://bugs.freedesktop.org/show_bug.cgi?id=30450

> Jamey was involved with this same problem a while ago. I provided patches
> but those weren't accepted, because the patches required such interface
> changes in libxcb that could have encouraged potentially dangerous use of
> the library.
> 
> The original patches can be found here:
> http://lists.freedesktop.org/archives/xcb/2010-October/006491.html. Some
> discussion followed and the patches weren't accepted.

It isn't obvious to me that any of the patches you proposed then address
the open bug that you describe below.

> Jamey told that he's trying to think of a fix using poll() in libX11 that
> wouldn't require interface changes in libxcb. Before proceeding he asked me
> to supply a fixed version of one patch from the previous series. I did that
> in http://lists.freedesktop.org/archives/xcb/2010-October/006516.html but it
> seems that the patch was forgotten, or Jamey has agreed with Josh not to
> apply it.

Forgotten then, pushed now. My apologies.

> > > Does anyone have a good idea of the causes of this problem and the
> > > effects it has? I think some in-depth analysis would be in order to
> > > solve the problem.
> 
> It seems that libX11 has suffered from this since
> http://cgit.freedesktop.org/xorg/lib/libX11/commit/?id=933aee1d5c53b0cc7d608011a29188b594c8d70b.
> All you have to do is wait for an event in one thread and wait for a reply
> in another one to trigger it. The reply waiter cannot continue until an
> event arrives. The _XReply and _XReadEvents functions of libX11 need to be
> fixed to solve this.
> 
> It's possible to fix this with interface changes in libxcb. It's probably
> possible to fix it without interface changes also, but that may be harder.

This is clearly affecting quite a few people, and needs fixing. 

I think Robert White has a point in
	https://bugs.freedesktop.org/show_bug.cgi?id=29561
A function like xcb_check_for_buffered_events may be sufficient API in
XCB to let Xlib solve the deadlock bug, as well as that one, using
select or poll.

Rami, I'd be interested in seeing the patches you wrote about having for
xcb_poll_for_queued_event.

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


More information about the Xcb mailing list