NPTL 和 POSIX 线程有什么区别?
NPTL 和 POSIX 线程之间的基本区别是什么?这两者是如何演变的?
What is the basic difference between NPTL and POSIX threads? How have these two evolved?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
POSIX 线程(pthread)不是一个实现,它是几个函数的 API 规范(纸上的标准,英文),其名称以
pthread_
开头,并在中定义。 pthread.h>
标头。 POSIX 也是一套规范。NPTL 现在位于 Linux 上的 GNU Libc 中,并且是(或者至少努力成为)POSIX 线程的实现。它是 Linux 系统上的一堆源代码和二进制代码。
现在,使用
gcc -pthread
编译并使用-pthread
链接的应用程序在 Linux 上使用 NPTL 代码。附录
pthread
-s 存在替代实现:在 Linux 上,MUSL Libc 旨在成为 Posix兼容(这意味着具有 pthreads);在其他 Posix 系统(AIX、Solaris...)上,您也有 pthread(但它们不是 NPTL 或 Glibc)。POSIX threads (pthread) is not an implementation, it is a API specification (a standard, on paper, in english) of several functions whose name starts with
pthread_
and which are defined in<pthread.h>
header. POSIX is also a set of specifications.NPTL is now inside GNU Libc on Linux and is (or at least tries very hard to be) an implementation of POSIX threads. It is a bunch of source and binary code on your Linux system.
An application compiled with
gcc -pthread
and linked with-pthread
uses NPTL code on Linux today.addenda
There exist alternative implementations of
pthread
-s: on Linux, the MUSL Libc aims to be Posix compliant (which means having pthreads); on other Posix systems (AIX, Solaris, ...) you also have pthreads (but they are not NPTL or Glibc).“POSIX 线程”是一个“标准”,定义了线程的 API。即它声明诸如 pthread_exit () 等函数应该存在于系统中,并描述它们应该如何表现。所有 POSIX 兼容操作系统都以自己的方式实现 POSIX 线程。
NPTL 是一系列功能,使“Linux”(内核)能够有效地实现“POSIX 线程”(标准)。
您可以在此处了解有关 NPTL 及其起源的更多信息
"POSIX threads" is a 'standard', defining an API for threading. i.e. it states that functions such as
pthread_exit ()
etc, should exist in the system, and describes how they should behave. All POSIX compliant operating systems implement POSIX threads in their own way.NPTL is a bunch of features that enables "Linux" (the kernel) to efficiently implement "POSIX threads" (the standard).
You can read more about NPTL and how it came about here
我想您最好的信息来源是从 Wikipedia 开始,然后点击那里的链接。
实际上没有什么区别:NPTL 只是 POSIX 线程的当前 Linux 实现,您仍然使用 pthread_* 系列函数。在 Linux 历史的早期,使用了一个名为 libpthreads 的专用库。 NPTL 出现于 2003 年左右的 2.6+ 内核,请参阅上面的链接了解更多详细信息。
[顺便说一句:NPTL == 本机 Posix 线程库]
I guess your best source of information is starting on Wikipedia and following the links from there.
There is really no difference: NPTL is just the current Linux implementation of POSIX threads, you still use the pthread_* family of functions. Earlier in Linux history, a dedicated library called libpthreads was used. NPTL appeared for 2.6+ kernels circa 2003, see the link above for more details.
[BTW: NPTL == Native Posix Threads Library]