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

Rami Ylimäki rami.ylimaki at vincit.fi
Tue Mar 15 02:26:38 PDT 2011


On 03/15/2011 03:19 AM, Jamey Sharp wrote:
>> 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.
>

Those patches were my first attempt to fix the event/reply deadlock. I 
wrote a test case for it, which seemed to pass with the fix. However, 
the patches were never tested thoroughly for an extended period of time 
and the fixes have now fallen into oblivion. It might very well be that 
something important was missed.

The test case was:
  - thread 1 waits for events (XNextEvent)
  - thread 2 executes a request (XSync) and finishes
  - main thread lets thread 1 to finish by mapping a window that sends 
an expose event

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

The patches that I have are meant to avoid excessive reading from the 
connection and I haven't attempted to fix the event/reply deadlock with 
them. I have made two separate fixes:

1) Fix unnecessary reading from connection in _XReply and _XReadEvents
http://gitorious.org/meego-w40/libxcb/commit/b1c1755236958d834d2e924d585fc40fd8c7d289
http://gitorious.org/meego-w40/libx11/commit/a1f5f909f9d98755519193b5e876c6aff679d040
http://gitorious.org/meego-w40/libx11/commit/b8784c3010bfeb5d80389dc8b7c38795237ce162

2) Clean up EAGAIN errors from read when connection is polled in 
_XEventsQueued
http://gitorious.org/meego-w40/libxcb/commit/291ddb5232280ee0dbd677d6dca759ac86cbd827
http://gitorious.org/meego-w40/libx11/commit/86d4a83cfd39765dd7c463d353aa22e468174eb4
http://gitorious.org/meego-w40/libx11/commit/ef09c42c9c7effcf8f539606d2e7d41b44bc0eb7

-- Rami



More information about the Xcb mailing list