IBM developerWorks 中國網站中,有一系列關於pthread的文章,對於pthread有初步而全面的介紹。特地將目錄轉成繁體字,摘錄如下。

 

小叮嚀:

因為對岸用語與我們不同,以下是一些常用詞:

內存=記憶體

內核=kernel

線程=thread

進程=process

原文出處:http://www.ibm.com/developerworks/cn/linux/theme/posix_thread/index.html

POSIX 線程

POSIX 線程詳解、POSIX 線程編程、NPTL

Page navigation

POSIX 表示可移植操作系統接口(Portable Operating System Interface ,縮寫為 POSIX 是為了讀音更像 UNIX)。電氣和電子工程師協會(Institute of Electrical and Electronics Engineers,IEEE)最初開發 POSIX 標準,是為了提高 UNIX 環境下應用程序的可移植性。具體的說 POSIX 是 IEEE 為要在各種 UNIX 操作系統上運行的軟件定義 API 所規定的一系列互相關聯的標準的總稱,而 X 則表明其對 Unix API 的傳承。Linux 基本上逐步實現了 POSIX 兼容,但並沒有參加正式的 POSIX 認證。當前的 POSIX 文檔分為三個部分:POSIX Kernel API,POSIX 命令和工具集,及 POSIX 一致性測試。Posix 線程(POSIX threads,又稱 Pthreads)是負責 POSIX 的 IEEE 委員會開發的一套線程接口。

Linux 線程模型

Linux 最初用的線程模型是 LinuxThread, 它不兼容 POSIX,而且存在一些性能問題,所以目前 Linux 摒棄了它,採用了基於 Pthreads 的 NPTL(Native POSIX Threads Library for Linux)模型, NPTL 修復了 LinuxThread 的許多缺點,並提供了更好的性能。

 

POSIX 線程詳解

Daniel Robbins 從實例入手,逐步講解 POSIX thread 編程技巧,有共享內存、互斥以及條件變量的運用。

 

Posix 線程編程指南

本系列文章在闡明概念的基礎上,向您詳細地講述了 Posix 線程庫 API。

     


    POSIX threads explained

    Common threads: POSIX threads explained, Part 2

    Common threads: POSIX threads explained, Part 3

     

    IBM developerWorks英文官網還有其他兩篇相關文章:

    Avoiding memory leaks in POSIX thread programming

    Basic use of pthreads

     

    • 這一篇文章則指出pthread在傳遞參數時潛藏的危機與解決方法,頗值一讀:

    Pthreads arguments passing

     

    • 這一篇文章提供一個實作pthread來讀寫stack的程式,並且利用Ncurses library來呈現實際效果,非常有趣,值得推薦。而且這是中文寫的,不必擔心語言問題:

    Multithread Programming Using Pthread

    我在實際compile 的時候,修改了一下Makefile才能PASS,提供修正後版本以供參考:

    CFLAGS = -lpthread -lncurses

    all: osproj3

    osproj3: src/osproj3.c
        gcc $? $(CFLAGS) -o $@

    clean:
        rm osproj3

     

    我的gcc版本如下:

    $ gcc -v
    Using built-in specs.
    Target: i386-redhat-linux
    Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --with-cpu=generic --host=i386-redhat-linux
    Thread model: posix
    gcc version 4.1.2 20070925 (Red Hat 4.1.2-27)
    $

     

    • 最後提供兩篇圖文並茂的教學文件:
    1. POSIX Threads Programming

    2. Linux Tutorial: POSIX Threads

    arrow
    arrow
      全站熱搜

      dragonspring 發表在 痞客邦 留言(0) 人氣()