What is the difference between NPTL and POSIX threads?

耗尽温柔 提交于 2019-12-20 10:21:15

问题


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


回答1:


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




回答2:


"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




回答3:


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]



来源:https://stackoverflow.com/questions/8576126/what-is-the-difference-between-nptl-and-posix-threads

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!