Native POSIX Thread Library: Difference between revisions

Content deleted Content added
Sigbusyff (talk | contribs)
History: Added notes on RHEL, and the fact that NPTL is now a feature of glibc.
Sigbusyff (talk | contribs)
Added more historical notes, reference to NGPT, quick explanation of 1x1 or mxn threading
Line 4:
 
== History ==
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 1x1 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 mxn, 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_switch|context switching of threads]] very fast, as it avoids system calls, but increases complexity and the likelihood of [[priority inversion]].
 
NPTL first 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 programming language|Java]] website about Java on Red Hat 9.