NPTL vs PThread

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.

Native POSIX Thread Library

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

History

Before the 2.6 version of the Linux kernel, processes were the schedulable entities, and there were no special facilities for threads. However, it did have a system call — clone — 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 threads (most of the previous thread implementations in Linux worked entirely in userland). Unfortunately, it only partially complied with POSIX, 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 new threading 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 after merging its best features into NPTL.

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 website about Java on Red Hat Linux 9.

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.

There exists a tracing tool for NPTL, called POSIX Thread Trace Tool (PTT). And an Open POSIX Test Suite (OPTS) was written for testing the NPTL library against the POSIX standard.

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 pthread_create() 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 m×n model.

NPTL vs PThread的更多相关文章

  1. Glibc-2.3.4编译

    $tar xf Glibc2.3.4.tar.bz2 $mkdir build_glibc $cd build_glibc ../glibc-2.3.4/configure --prefix=/too ...

  2. 正确使用pthread_create,防止内存泄漏

    近日,听说pthread_create会造成内存泄漏,觉得不可思议,因此对posix(nptl)的线程创建和销毁进行了分析.   分析结果:如果使用不当,确实会造成内存泄漏. 产生根源:pthread ...

  3. 具体分析contrex-A9的汇编代码__switch_to(进程切换)

    //函数原型:版本号linux-3.0.8 struct task_struct *__switch_to(structtask_struct *, struct thread_info *, str ...

  4. POSIX多线程

    全文共分四部分: POSIX多线程—概述    POSIX多线程—异步编程举例    POSIX多线程—线程基本概念    POSIX多线程—互斥量概述 POSIX多线程—概述 Content 1. ...

  5. life of a NPTL pthread

    这是2013年写的一篇旧文,放在gegahost.net上面 http://raison.gegahost.net/?p=91 March 7, 2013 life of a NPTL pthread ...

  6. Linux线程的实现 & LinuxThread vs. NPTL & 用户级内核级线程 & 线程与信号处理

    另,线程的资源占用可见:http://www.cnblogs.com/charlesblc/p/6242111.html 进程 & 线程的很多知识可以看这里:http://www.cnblog ...

  7. pthread多线程编程的学习小结

    pthread多线程编程的学习小结  pthread 同步3种方法: 1 mutex 2 条件变量 3 读写锁:支持多个线程同时读,或者一个线程写     程序员必上的开发者服务平台 —— DevSt ...

  8. posix 线程(一):线程模型、pthread 系列函数 和 简单多线程服务器端程序

    posix 线程(一):线程模型.pthread 系列函数 和 简单多线程服务器端程序 一.线程有3种模型,分别是N:1用户线程模型,1:1核心线程模型和N:M混合线程模型,posix thread属 ...

  9. Linux多线程编程和Linux 2.6下的NPTL

    Linux多线程编程和Linux 2.6下的NPTL 在Linux 上,从内核角度而言,基本没有什么线程和进程的区别--大家都是进程.一个进程的多个线程只是多个特殊的进程他们虽然有各自的进程描述结构, ...

随机推荐

  1. TCP三次握手四次挥手

    看到一篇总结很好的TCP三次握手,学习一下,原文链接. 建立TCP需要三次握手才能建立,而断开连接则需要四次握手.整个过程如下图所示: 先来看看如何建立连接的. 首先Client端发送连接请求报文,S ...

  2. 最后一周psp

    团队项目PSP 一:表格     C类型 C内容 S开始时间 E结束时间 I时间间隔 T净时间(mins) 预计花费时间(mins) 讨论 讨论用户界面 10:20 11:45 25 40 80 分析 ...

  3. SageCRM 快速获取连接中的SID的方法

    经常需要使用ajax来修改页面的功能,包括联动.动态加载等. SageCRM的页面必须有SID的,所以要方便的获取它. var getKey = function(key,Url) { if(argu ...

  4. SQLServer存储过程事务用法

    更多资源:http://denghejun.github.io IF object_id('InsertAntennaProcedure') IS NOT NULL DROP PROCEDURE In ...

  5. ENode框架Conference案例分析系列之 - 事件溯源如何处理重构问题

    前言 本文可能对大多数不太了解ENode的朋友来说,理解起来比较费劲,这篇文章主要讲思路,而不是一上来就讲结果.我写文章,总是希望能把自己的思考过程尽量能表达出来,能让大家知道每一个设计背后的思考的东 ...

  6. Mysql 主从延时监控

    200 ? "200px" : this.width)!important;} --> 介绍 主从延时在主从环境中是一个非常值得关注的问题,有时候我们可以通过show sla ...

  7. Web3DGame之路,Babylonjs 和TypeScript学习笔记(二)

    先来认识一下Babylonjs,由于基于webgl来开发,所以先介绍一下基础知识. Webgl是一个html标准,他要在canvas元素上初始化. Html页面上的准备 所以我们先从html页面开始看 ...

  8. 使用Hexo搭建专属Blog

    喜欢折腾的自己最开始在博客园有仿写几篇Blog,虽也可以自己改变风格,可是到底不是独立的一块儿地方,要知道独立的才是自己的;有属于自己独立的域名和Blog,真真是一件很爽的存在.在各种大牛的分享下在G ...

  9. Atitti 大话存储读后感 attilax总结

    Atitti 大话存储读后感 attilax总结 1.1. 大话存储中心思想(主要讲了磁盘文件等存储)1 1.2. 最耐久的存储,莫过于石头了,要想几千万年的存储信息,使用石头是最好的方式了1 1.3 ...

  10. Selenium WebDriver 3.0 需要注意的事项

    以下所有代码基于Java 首先,要使用WebDriver 3.0 的话 请使用JAVA 8(必要)   其次,由于W3C标准化以及各大浏览器厂商的积极跟进,自WebDriver 3.0 之后,Sele ...