Native POSIX Thread Library

From Academic Kids

In the Linux operating system, the Native POSIX Thread Library (NPTL) is a software feature that enables the Linux kernel to run programs written to use POSIX-style threads very efficiently.

In tests, NPTL succeeded in running 100,000 threads simultaneously on a IA-32 which were started in two seconds. In comparison, this test under a kernel without NPTL would have taken around 15 minutes.


Historically (i.e before the 2.6 kernel), Linux supports processes as a schedulable entity, and has no real support for threads in the kernel. However, it does support a system call - clone() - which creates a copy of the calling process, where the copy shares the address space of the caller. The LinuxThreads project used this system call to simulate thread support entirely in userland; unfortunately, it had a number of issues with true POSIX compliance, particularly in the areas of signal handling, scheduling, and inter-process synchronization primitives.

To improve on LinuxThreads, it was clear that some kernel support, and a re-written threads library, would be required. Two competing projects were started to address the requirement - NGPT, or Next Generation POSIX Threads, was worked on by a team including developers from IBM; NPTL was worked on in parallel by developers at Red Hat. NGPT was abandoned in mid-2003.

NPTL uses a similar approach to LinuxThreads, in that the primary abstraction known by the kernel is still a process, and new threads are created with the clone() system call (called from the NPTL library). However, NPTL requires specialised kernel support to implement (for example) the contended case of synchronisation primitives which might require threads to sleep and be re-awoken. The primitive used for this is known as a futex.

NPTL is a so-called 1×1 threads library, in that threads created by the user (via the pthread_create() library function) are in 1-1 correspondence with schedulable entities in the kernel (processes, in the Linux case). This is the simplest possible threading implementation; an alternative is m×n, where there are typically more userland threads than schedulable entities. In this implementation, the threading library is responsible for scheduling user threads on the available schedulable entities; this makes context switching of threads very fast, as it avoids system calls, but increases complexity and the likelihood of priority inversion.

NPTL was first released in Red Hat 9.0. Old-style POSIX threading is known for having trouble with threads that refuse to yield to the system occasionally because it does not take the opportunity to preemptively yield them when it arises, something that Windows was known to do better at the time. Red Hat claimed that NPTL fixed this problem in an article on the Java website about Java on Red Hat 9.

NPTL has been part of Red Hat Enterprise Linux since version 3, and is now a fully integrated part of glibc.

NPTL vs. Windows threading experiments

In research done by Edward Rice in February of 2004, NPTL was compared to the Windows Threading Library. A program written in Java created multiple threads that ran at the same time. This program was run on both Windows and Linux on a dual boot system Intel non-hyper-threading chipset. It was discovered that Windows handled threads that yielded often better than Red Hat Linux 9, but Red Hat Linux 9 handled threads that yielded less frequently better than Windows. It was concluded that this was the result of the time it takes for a thread to yield and the virtual machine to pick a new one .

See also


Academic Kids Menu

  • Art and Cultures
    • Art (
    • Architecture (
    • Cultures (
    • Music (
    • Musical Instruments (
  • Biographies (
  • Clipart (
  • Geography (
    • Countries of the World (
    • Maps (
    • Flags (
    • Continents (
  • History (
    • Ancient Civilizations (
    • Industrial Revolution (
    • Middle Ages (
    • Prehistory (
    • Renaissance (
    • Timelines (
    • United States (
    • Wars (
    • World History (
  • Human Body (
  • Mathematics (
  • Reference (
  • Science (
    • Animals (
    • Aviation (
    • Dinosaurs (
    • Earth (
    • Inventions (
    • Physical Science (
    • Plants (
    • Scientists (
  • Social Studies (
    • Anthropology (
    • Economics (
    • Government (
    • Religion (
    • Holidays (
  • Space and Astronomy
    • Solar System (
    • Planets (
  • Sports (
  • Timelines (
  • Weather (
  • US States (


  • Home Page (
  • Contact Us (

  • Clip Art (
Personal tools