[Xcb] Portability problem; some libcs don't provide pthread stubs

Barton C Massey bart at cs.pdx.edu
Thu Sep 28 03:08:33 PDT 2006

In message <451B959B.7060704 at freedesktop.org> you wrote:
> libxcb makes use of pthreads functions, such as pthread_mutex_lock,
> internally.  However, libxcb does not require that applications link
> with -lpthread; we want people who link with -lpthread to get thread
> functions and a thread-safe libxcb, while allowing people who don't link
> with -lpthread to avoid the overhead.  In order to do this, we rely on
> the libc stubs for pthread functions.  However, apparently several
> platforms, including OSF, AIX, and Hurd, do not provide pthread stubs in
> libc.  Thus, when attempting to link an application with libxcb, the
> linker fails with undefined symbol errors for pthread functions unless
> the application links with -lpthread.
> After speaking with several people via IRC, it sounds like the best fix
> to preserve existing behavior on these platforms requires checking for
> pthread stubs via autoconf, and if not available, defining them in
> libxcb as weak aliases, like libX11 does without #define XTHREADS:
> int pthread_mutex_init()    __attribute__ ((weak, alias
> ("_Xthr_zero_stub_")));
> static int
> _Xthr_zero_stub_()
> {
>     return(0);
> }
> - Josh Triplett

Jamey and I knew this day would come eventually.  I'd be
comfortable with your suggested solution.

I'd also be comfortable with just requiring folks to link
against libpthreads on those platforms.  Presumably,
pkgconfig would take care of supplying this requirement if
told to do so by autoconf.  I'm not at all convinced the
runtime overheads of the extra locking are significant.


More information about the Xcb mailing list