手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>网站运营>建站经验>列表

POSIX Thread Tutorial

来源:互联网 作者:west263.com 时间:2008-04-16
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!
Getting the Source


Latest News on this Document

1 May 1998:

The code and documentation contained herein now conforms to POSIX 1003.1c-1995. The previous version of this document is based on POSIX 1003.1c draft 4 which (AFAIK) only works on DEC OSF/1 3.2. The old code can still be downloaded here if you need it; however, the draft 4 code will no longer be maintained.

The revised code described here has only been tested on Linux systems (LinuxThreads and glibc native threads). If you encounter problems or have corrections, please send an email to system.


What are threads?
A thread is a sequence of instructions to be executed within a program. Normal UNIX processes consist of a single thread of execution that starts in main(). In other words, each line of your code is executed in turn, exactly one line at a time. Before threads, the normal way to achieve multiple instruction sequences (ie, doing several things at once, in parallel) was to use the fork() and exec() system calls to create several processes -- each being a single thread of execution.

In the UNIX operating system, every process has the following:

1. a virtual address space (ie, stack, data, and code segments)

2. system resources (eg, open files)

3. a thread of execution

These resources are private to each process; for example, processes cannot peek into one another's address space, open and close files for one another, etc. To achieve interprocesses cooperation, external channels (to the process) of communication are needed. UNIX systems provide several mechanisms for accomplishing interprocess communication (IPC), including (relevant manpages are listed in square brackets):