[Xcb] POSIX threads cancellation / VLC

Josh Triplett josh at joshtriplett.org
Tue Dec 15 00:23:44 PST 2009

On Tue, Dec 15, 2009 at 07:54:13AM +0100, Rémi Denis-Courmont wrote:
> I am happy to announce that VLC media player (what will become vesion
> 1.1.0) has been almost completely ported to XCB. Namely, the X11 and XVideo
> outputs, the screen capture input, the (new) screen capture wizard, the
> windowing code, the "global hotkeys", and the seldom used panaromic video
> filter are now purely XCB-based. Also, the GLX output was rewritten to
> X11-XCB. This just leave the Qt4 UI, the VAAPI bindings to libavcodec, and
> the skin engine using Xlib.

Incredibly awesome!  Thank you for telling us about this!

> The main driver for XCB was saner error/event handling and thread safety.
> It was practically impossible to use Xlib properly with the multi-thread
> and plugin-based architecture that VLC has. Also, this was a good
> opportunity to rebuild our X11 competence and refactor the aging code.

Glad to hear you've had a good experience with those particular pieces
of XCB; we spent a disproportionately large amount of effort getting
those pieces *right*, making it really gratifying to hear that we
succeeded.  Thank you!

> Anyway. VLC uses *synchronous* thread cancellation in many code paths, and
> our XCB event handling looks like:
> for (;;)
> {
>     poll(xcb_fd);
>     disable_cancel();
>     handle_xcb_events...;
>     enable_cancel();
> }
> This is not terribly efficient. We could use XCB in blocking mode, but we
> need to catch the cancel signal from a safe place. So I'm wondering if
> handling thread cancellation directly inside XCB would be acceptable.
> Mostly, this means installing cleanup handlers in strategic places, and
> disabling cancellation in some other ones in the core XCB code.

Handling cancellation seems fairly reasonable.  We've used pthreads in
XCB, so that makes it fairly reasonable that we ought to support
the use of pthreads functionality, including cancellation.

> I had a partial patch for this, but I wouldn't bother rebasing it you guys
> don't like the idea at all.

I'd like to see the patch.  Please do go ahead and send it.  You don't
necessarily have to go to the trouble of rebasing it before sending it,
if you've written it against a relatively recent XCB.  Go ahead and send
it, tell us what version it applies to, and we can evaluate it enough to
get the idea and figure out if you should go ahead and rebase.

- Josh Tiplett

More information about the Xcb mailing list