Handling of client-side multi-threading in X

Locking in X libraries

[Describe here what kind of locking is needed by X libs and how it's implemented]

Configure options

libX11

  • --disable-xthreads disables threads support in libX11 (default: enabled).

Pre-processor symbols

Defined and used by X:

  • XTHREADS defined whenever libX11 is built with threads support.
  • XUSE_MTSAFE_API defined if libc has getpwuid_r() and getpwnam_r()

Used by OS headers and set by X:

  • _POSIX_THREAD_SAFE_FUNCTIONS
  • _REENTRANT

Header Files

There are several X headers related to threads

Xos_r.h

[Describe here the role of and when it needs to be included.]

Xthreads.h

[Describe here the role of and when it needs to be included.]

Threads libraries

Xlib and the associated libraries can support various threading libraries from the operating system they run on.

  • POSIX pthreads
  • Microsoft Windows threads
  • DEC Threads

Support for both threaded and non threaded applications

Since not all systems support threads by default in their basic C libraries, Xlib has some support for emulating threads support when it's not present in libc, so that the same library can be used in applications built with or without thread support.

This support is provided throught a set of weak symbols function pointers that define stub implementatons of the threading functions that may be called by thread-aware code. When a real theading implementation is present, the weak definitions are ignored, and the code will call the real functions from the system's threading library. If on threading implemnentation the stubs functions pointed at by the weak symbols will be called. Those stubs are no-op that only make sense in a thread-less environment of course.

Those stubs are implemented for various systems in UIThrStubs.c

XCB Support

[Describe here how using XCB alone or XCB -enabled libX11 changes things]