Determining PThread Library Type

Linux kernel versions prior to 2.6 did not offer good internal support for threads. Therefore a threading library called LinuxThreads was used to provide most of the POSIX PThread API.

Since Linux 2.6 good threading support was added to the Linux kernel and a new library, called NPTL for New Posix Threading Library was created to provide scalable, robust POSIX compliant threading support in Linux.

As both libraries use the same POSIX API, code written for one will usually work with the other as is, but not always. It is therefore some time desirable to be able to learn in run time which threading library is being used.

The following code example shows how this can be done:

#define _XOPEN_SOURCE
#include <unistd.h>
#include <stdio.h>
 
int main(void)
{
  char name[128];
  confstr (_CS_GNU_LIBPTHREAD_VERSION,  name, sizeof(name));
  printf ("Pthreads lib: %s\n", name);
  return 0;
}