Linux NPTL 和 POSIX 线程有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8576126/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 03:44:39  来源:igfitidea点击:

What is the difference between NPTL and POSIX threads?

linuxpthreadsposixnptl

提问by Whoami

What is the basic difference between NPTL and POSIX threads? How have these two evolved?

NPTL 和 POSIX 线程之间的基本区别是什么?这两个是怎么进化的?

采纳答案by Basile Starynkevitch

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.

POSIX 线程 (pthread) 不是一个实现,它是几个函数的 API 规范(一种标准,纸上,英文),其名称以 开头pthread_并在<pthread.h>头文件中定义。POSIX 也是一套规范。

NPTL is now inside GNU Libcon 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 -pthreadand linked with -pthreaduses NPTL code on Linux today.

NPTL 现在位于Linux 上的GNU Libc 中,并且是(或至少非常努力地尝试成为)POSIX 线程的实现。它是 Linux 系统上的一堆源代码和二进制代码。使用 NPTL 代码编译gcc -pthread和链接的应用程序-pthread今天在 Linux 上使用。

addenda

附加物

There exist alternative implementations of pthread-s: on Linux, the MUSL Libcaims 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).

pthread-s存在替代实现:在 Linux 上,MUSL Libc旨在符合 Posix(这意味着具有 pthreads);在其他 Posix 系统(AIX、Solaris 等)上,您也有 pthread(但它们不是 NPTL 或 Glibc)。

回答by fge

I guess your best source of information is starting on Wikipediaand 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.

真的没有区别:NPTL 只是 POSIX 线程的当前 Linux 实现,您仍然使用 pthread_* 系列函数。在 Linux 历史的早期,使用了一个名为 libpthreads 的专用库。NPTL 在 2003 年左右出现在 2.6+ 内核中,有关更多详细信息,请参阅上面的链接。

[BTW: NPTL == Native Posix Threads Library]

[顺便说一句:NPTL == 原生 Posix 线程库]

回答by ArjunShankar

"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.

“POSIX 线程”是一个“标准”,定义了用于线程处理的 API。即它声明pthread_exit ()系统中应该存在诸如etc之类的功能,并描述它们应该如何表现。所有符合 POSIX 的操作系统都以自己的方式实现 POSIX 线程。

NPTL is a bunch of features that enables "Linux" (the kernel) to efficiently implement "POSIX threads" (the standard).

NPTL 是一系列特性,使“Linux”(内核)能够有效地实现“POSIX 线程”(标准)。

You can read more about NPTL and how it came about here

您可以在此处阅读有关 NPTL 以及它是如何产生的更多信息