Native POSIX Thread Library: Difference between revisions

Content deleted Content added
Undid revision 375866873 by Trasz (talk)
Bender the Bot (talk | contribs)
m HTTP to HTTPS for SourceForge
 
(34 intermediate revisions by 29 users not shown)
Line 1:
The '''Native POSIX Thread Library''' ('''NPTL''') is aan softwareimplementation feature that enablesof the [[LinuxPOSIX kernelThreads]] tospecification runfor programs written to usethe [[POSIX ThreadsLinux]] efficientlyoperating system.
 
== History ==
In tests, NPTL succeeded in starting 100,000 [[Thread (computer science)|threads]] on a [[IA-32]] in two seconds. In comparison, this test under a kernel without NPTL would have taken around 15 minutes.<ref>[http://www.linuxjournal.com/article/6530 Introducing the 2.6 Kernel<!-- Bot generated title -->]</ref><ref>[http://people.redhat.com/drepper/nptl-design.pdf The Native POSIX Thread Library for Linux<!-- Bot generated title -->]</ref>
Before the 2.6 version of the [[Linux kernel]], processes were the schedulable entities, and there were no special facilities for [[Thread (computer science)|threads]].<ref>[https://web.archive.org/web/20210929083526/https://man7.org/linux/man-pages/man7/pthreads.7.html pthreads(7) — Linux manual page]</ref>
Before the 2.6 version of the [[Linux kernel]], processes were the schedulable entities, and there was no real support for [[Thread (computer science)|threads]]. However, it did supporthave a [[system call]] — <tt>{{mono|[[clone (Linux system call)#Clone|clone]]</tt>}} — 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 provide kernel-level thread supportthreads (most of the previous pthreadthread implementations in Linux worked entirely in [[Userland (computing)|userland]]). Unfortunately, it hadonly apartially number of issuescomplied with true POSIX compliance, particularly in the areas of signal handling, scheduling, and inter-process synchronization primitives.
 
To improve upon LinuxThreads, it was clear that some kernel support and a re-writtennew threadsthreading library would be required. Two competing projects were started to address the requirement: [[NGPT]] (Next Generation POSIX Threads) worked on by a team which included developers from [[IBM]], and NPTL by developers at [[Red Hat]]. The NGPT team collaborated closely with the NPTL team and combined the best features of both implementations into NPTL. The NGPT project was subsequently abandoned in mid-2003, atafter aboutmerging theits samebest timefeatures wheninto NPTL was released.
== History ==
 
NPTL was first released in Red Hat Linux 9. Old-style Linux 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 preempt 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 Linux 9.<ref>[https://web.archive.org/web/20110604035631/http://java.sun.com/developer/technicalArticles/JavaTechandLinux/RedHat/ Red Hat Linux 9 and Java 2 Platform, Standard Edition 1.4.2: A Winning Combination]</ref>
Before the 2.6 version of the [[Linux kernel]], processes were the schedulable entities, and there was no real support for [[Thread (computer science)|threads]]. However, it did support a [[system call]] — <tt>[[clone (Linux system call)|clone]]</tt> — 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 provide kernel-level thread support (most of the previous pthread implementations in Linux worked entirely in [[Userland (computing)|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.
 
NPTL has been part of [[Red Hat Enterprise Linux]] since version 3, and in the Linux kernel since version 2.6. It is now a fully integrated part of the [[GNU C Library]].<ref>[http://lists.gnu.org/archive/html/info-gnu/2004-08/msg00002.html GNU C Library version 2.3.3 release]</ref>
To improve upon 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]] (Next Generation POSIX Threads) worked on by a team which included developers from [[IBM]], and NPTL by developers at [[Red Hat]]. NGPT was abandoned in mid-2003, at about the same time when NPTL was released.
 
There exists a tracing tool for NPTL, called [httphttps://nptltracetool.sourceforge.net/ POSIX Thread Trace Tool] ([http://sourceforge.net/projects/nptltracetool/ PTT]). And an [http://posixtest.sourceforge.net/ Open POSIX Test Suite] ([httphttps://sourceforge.net/projects/posixtest/ OPTS]) was written for testing the NPTL library against the POSIX standard.
NPTL was first released in Red Hat Linux 9. Old-style Linux 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 preempt 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 Linux 9.<ref>[http://java.sun.com/developer/technicalArticles/JavaTechandLinux/RedHat/ Red Hat Linux 9 and Java 2 Platform, Standard Edition 1.4.2: A Winning Combination]</ref>
 
== Design ==
NPTL has been part of [[Red Hat Enterprise Linux]] since version 3, and in the Linux kernel since version 2.6. It is now a fully integrated part of the [[GNU C Library]].
Like LinuxThreads, NPTL is a 1:1 threads library. Threads created by the library (via ''pthread_create'') correspond one-to-one with schedulable entities in the kernel (''processes'', in the Linux case).<ref name="lsp-love">{{Cite book |title=Linux System Programming |author=Robert Love |edition=2nd |isbn=978-1449339531 |date=2013|publisher=O'Reilly Media, Incorporated }}</ref>{{rp|226}} This is the simplest of the three [[Thread (computing)#Threading models|threading models]] (1:1, N:1, and M:N).<ref name="lsp-love"></ref>{{rp|215–216}} New threads are created with the clone() [[system call]] called through the NPTL library. NPTL relies on kernel support for [[futex]]es to more efficiently implement user-space locks.<ref name="lsp-love"></ref>{{rp|182}}
 
== See also ==
There exists a tracing tool for NPTL, called [http://nptltracetool.sourceforge.net/ POSIX Thread Trace Tool] ([http://sourceforge.net/projects/nptltracetool/ PTT]). And an [http://posixtest.sourceforge.net/ Open POSIX Test Suite] ([http://sourceforge.net/projects/posixtest/ OPTS]) was written for testing the NPTL library against the POSIX standard.
{{Portal|Free and open-source software}}
 
== Design ==
 
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 specialized kernel support to implement (for example) the contended case of synchronisation primitives which might require threads to sleep and wake again. 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 <code>pthread_create()</code> library function) are in 1-1 correspondence with schedulable entities in the kernel (tasks, in the Linux case). This is the simplest possible threading implementation.
 
An alternative to NPTL's 1×1 model is the [[Thread_%28computer_science%29#N:M_.28Hybrid_threading.29|''m×n'' model]]
 
== See also ==
{{Portal|Free software}}
 
* [[LinuxThreads]]
Line 31 ⟶ 24:
 
==References==
 
{{Reflist}}
 
==External links==
* [httphttps://nptltracetool.sourceforge.net/ NPTL Trace Tool] OpenSource tool to trace and debug multithreaded applications using the NPTL.
* [http://people.redhat.com/drepper/nptl-design.pdf NPTL Design paper]
 
* [http://nptltracetool.sourceforge.net/ NPTL Trace Tool] OpenSource tool to trace and debug multithreaded applications using the NPTL.
{{Linux}}
 
{{DEFAULTSORT:Native Posix Thread Library}}
[[Category:Linux kernel]]
[[Category:C POSIX standardslibrary]]
[[Category:Threads (computing)]]
 
[[de:Native POSIX Thread Library]]
[[ja:Native POSIX Thread Library]]
[[pl:Native POSIX Thread Library]]
[[pt:Native POSIX Thread Library]]
[[ru:Библиотека потоков POSIX]]
[[fi:Native POSIX Thread Library]]
[[zh:Native POSIX Thread Library]]