1PTHREADS(7)                Linux Programmer's Manual               PTHREADS(7)
2
3
4

NAME

6       pthreads - POSIX threads
7

DESCRIPTION

9       POSIX.1  specifies  a  set  of interfaces (functions, header files) for
10       threaded programming commonly known as POSIX threads, or  Pthreads.   A
11       single process can contain multiple threads, all of which are executing
12       the same program.  These threads share the same global memory (data and
13       heap  segments),  but  each  thread  has its own stack (automatic vari‐
14       ables).
15
16       POSIX.1 also requires that threads share a range  of  other  attributes
17       (i.e., these attributes are process-wide rather than per-thread):
18
19       -  process ID
20
21       -  parent process ID
22
23       -  process group ID and session ID
24
25       -  controlling terminal
26
27       -  user and group IDs
28
29       -  open file descriptors
30
31       -  record locks (see fcntl(2))
32
33       -  signal dispositions
34
35       -  file mode creation mask (umask(2))
36
37       -  current directory (chdir(2)) and root directory (chroot(2))
38
39       -  interval timers (setitimer(2)) and POSIX timers (timer_create())
40
41       -  nice value (setpriority(2))
42
43       -  resource limits (setrlimit(2))
44
45       -  measurements of the consumption of CPU time (times(2)) and resources
46          (getrusage(2))
47
48       As well as the stack, POSIX.1 specifies that various  other  attributes
49       are distinct for each thread, including:
50
51       -  thread ID (the pthread_t data type)
52
53       -  signal mask (pthread_sigmask())
54
55       -  the errno variable
56
57       -  alternate signal stack (sigaltstack(2))
58
59       -  real-time  scheduling policy and priority (sched_setscheduler(2) and
60          sched_setparam(2))
61
62       The following Linux-specific features are also per-thread:
63
64       -  capabilities (see capabilities(7))
65
66       -  CPU affinity (sched_setaffinity(2))
67
68   Compiling on Linux
69       On Linux, programs that use the Pthreads API should be  compiled  using
70       cc -pthread.
71
72   Linux Implementations of POSIX Threads
73       Over  time, two threading implementations have been provided by the GNU
74       C library on Linux:
75
76       -  LinuxThreads This is the original (now obsolete) Pthreads  implemen‐
77          tation.
78
79       -  NPTL  (Native  POSIX  Threads  Library)  This is the modern Pthreads
80          implementation.  By  comparison  with  LinuxThreads,  NPTL  provides
81          closer  conformance to the requirements of the POSIX.1 specification
82          and better performance when creating large numbers of threads.  NPTL
83          requires features that are present in the Linux 2.6 kernel.
84