[Xcb] Thread safety of XCB.

John Found johnfound at evrocom.net
Tue Oct 2 22:55:25 PDT 2012

Thanks for the reply.

On Tue, 2 Oct 2012 20:58:45 -0700
Josh Triplett <josh at joshtriplett.org> wrote:

> First of all, since you use threads with Xlib, you must call
> XInitThreads before any other call to Xlib, including XOpenDisplay.
> Have you done so?

Yes, my application calls XInitThreads before any other XLib call.

> Second, even though you don't use pthreads, Xlib and XCB do so
> internally; specifically, they use pthread locks and condition variables
> for synchronization.  If your application does not link to libpthread,
> those internal uses will go to the stub functions in glibc (or the stub
> functions in libpthread-stubs on systems without stubs in their libc), which don't
> actually do proper locking.  So, if you use threading with Xlib or XCB,
> you must compile with -pthread, even if you don't use libpthread
> yourself.  (Or, alternatively, you can call Xlib and XCB exclusively
> from a single thread.)

I am using XLib as a shared library, so I am sure it does calls the proper 
pthread functions, not the stubs in the glibc.
So, all synchronizations should be OK, except if XCB somehow accepts all of
my thread calls (created by sys_clone) as a single thread calls.

Is it possible and how I can set the proper behaviour?

John Found 

More information about the Xcb mailing list