Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between NPTL and POSIX threads?

Tags:

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

like image 641
Whoami Avatar asked Dec 20 '11 13:12

Whoami


People also ask

What is NPTL in Linux?

The Native POSIX Thread Library (NPTL) is an implementation of the POSIX Threads specification for the Linux operating system.

What is Posix thread in operating system?

POSIX Threads, commonly known as pthreads, is an execution model that exists independently from a language, as well as a parallel execution model. It allows a program to control multiple different flows of work that overlap in time.

Are POSIX Threads kernel threads?

A Pthread is the POSIX specification for thread behavior, so is an abstraction, which the systems programmer sees and directly uses. A kernel thread is the entity actually created, scheduled and managed by the kernel as the context to execute a thread in a process.

Do POSIX Threads work on Windows?

An implementation of the POSIX threads API for Windows Also known as "pthreads-win32", POSIX Threads for Windows implements a large subset of the threads related API from the Single Unix Specification Version 3.


2 Answers

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

like image 153
Basile Starynkevitch Avatar answered Oct 17 '22 02:10

Basile Starynkevitch


"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

like image 38
ArjunShankar Avatar answered Oct 17 '22 01:10

ArjunShankar