|
Packit |
7cfc04 |
'\" t
|
|
Packit |
7cfc04 |
.\" Copyright (c) 2005 by Michael Kerrisk <mtk.manpages@gmail.com>
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" %%%LICENSE_START(VERBATIM)
|
|
Packit |
7cfc04 |
.\" Permission is granted to make and distribute verbatim copies of this
|
|
Packit |
7cfc04 |
.\" manual provided the copyright notice and this permission notice are
|
|
Packit |
7cfc04 |
.\" preserved on all copies.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" Permission is granted to copy and distribute modified versions of this
|
|
Packit |
7cfc04 |
.\" manual under the conditions for verbatim copying, provided that the
|
|
Packit |
7cfc04 |
.\" entire resulting derived work is distributed under the terms of a
|
|
Packit |
7cfc04 |
.\" permission notice identical to this one.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
Packit |
7cfc04 |
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
|
Packit |
7cfc04 |
.\" responsibility for errors or omissions, or for damages resulting from
|
|
Packit |
7cfc04 |
.\" the use of the information contained herein. The author(s) may not
|
|
Packit |
7cfc04 |
.\" have taken the same level of care in the production of this manual,
|
|
Packit |
7cfc04 |
.\" which is licensed free of charge, as they might when working
|
|
Packit |
7cfc04 |
.\" professionally.
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
Packit |
7cfc04 |
.\" the source, must acknowledge the copyright and authors of this work.
|
|
Packit |
7cfc04 |
.\" %%%LICENSE_END
|
|
Packit |
7cfc04 |
.\"
|
|
Packit |
7cfc04 |
.TH PTHREADS 7 2017-09-15 "Linux" "Linux Programmer's Manual"
|
|
Packit |
7cfc04 |
.SH NAME
|
|
Packit |
7cfc04 |
pthreads \- POSIX threads
|
|
Packit |
7cfc04 |
.SH DESCRIPTION
|
|
Packit |
7cfc04 |
POSIX.1 specifies a set of interfaces (functions, header files) for
|
|
Packit |
7cfc04 |
threaded programming commonly known as POSIX threads, or Pthreads.
|
|
Packit |
7cfc04 |
A single process can contain multiple threads,
|
|
Packit |
7cfc04 |
all of which are executing the same program.
|
|
Packit |
7cfc04 |
These threads share the same global memory (data and heap segments),
|
|
Packit |
7cfc04 |
but each thread has its own stack (automatic variables).
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
POSIX.1 also requires that threads share a range of other attributes
|
|
Packit |
7cfc04 |
(i.e., these attributes are process-wide rather than per-thread):
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
process ID
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
parent process ID
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
process group ID and session ID
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
controlling terminal
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
user and group IDs
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
open file descriptors
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
record locks (see
|
|
Packit |
7cfc04 |
.BR fcntl (2))
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
signal dispositions
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
file mode creation mask
|
|
Packit |
7cfc04 |
.RB ( umask (2))
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
current directory
|
|
Packit |
7cfc04 |
.RB ( chdir (2))
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
root directory
|
|
Packit |
7cfc04 |
.RB ( chroot (2))
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
interval timers
|
|
Packit |
7cfc04 |
.RB ( setitimer (2))
|
|
Packit |
7cfc04 |
and POSIX timers
|
|
Packit |
7cfc04 |
.RB ( timer_create (2))
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
nice value
|
|
Packit |
7cfc04 |
.RB ( setpriority (2))
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
resource limits
|
|
Packit |
7cfc04 |
.RB ( setrlimit (2))
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
measurements of the consumption of CPU time
|
|
Packit |
7cfc04 |
.RB ( times (2))
|
|
Packit |
7cfc04 |
and resources
|
|
Packit |
7cfc04 |
.RB ( getrusage (2))
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
As well as the stack, POSIX.1 specifies that various other
|
|
Packit |
7cfc04 |
attributes are distinct for each thread, including:
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
thread ID (the
|
|
Packit |
7cfc04 |
.I pthread_t
|
|
Packit |
7cfc04 |
data type)
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
signal mask
|
|
Packit |
7cfc04 |
.RB ( pthread_sigmask (3))
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
the
|
|
Packit |
7cfc04 |
.I errno
|
|
Packit |
7cfc04 |
variable
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
alternate signal stack
|
|
Packit |
7cfc04 |
.RB ( sigaltstack (2))
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
real-time scheduling policy and priority
|
|
Packit |
7cfc04 |
.RB ( sched (7))
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
The following Linux-specific features are also per-thread:
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
capabilities (see
|
|
Packit |
7cfc04 |
.BR capabilities (7))
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
CPU affinity
|
|
Packit |
7cfc04 |
.RB ( sched_setaffinity (2))
|
|
Packit |
7cfc04 |
.SS Pthreads function return values
|
|
Packit |
7cfc04 |
Most pthreads functions return 0 on success, and an error number on failure.
|
|
Packit |
7cfc04 |
Note that the pthreads functions do not set
|
|
Packit |
7cfc04 |
.IR errno .
|
|
Packit |
7cfc04 |
For each of the pthreads functions that can return an error,
|
|
Packit |
7cfc04 |
POSIX.1-2001 specifies that the function can never fail with the error
|
|
Packit |
7cfc04 |
.BR EINTR .
|
|
Packit |
7cfc04 |
.SS Thread IDs
|
|
Packit |
7cfc04 |
Each of the threads in a process has a unique thread identifier
|
|
Packit |
7cfc04 |
(stored in the type
|
|
Packit |
7cfc04 |
.IR pthread_t ).
|
|
Packit |
7cfc04 |
This identifier is returned to the caller of
|
|
Packit |
7cfc04 |
.BR pthread_create (3),
|
|
Packit |
7cfc04 |
and a thread can obtain its own thread identifier using
|
|
Packit |
7cfc04 |
.BR pthread_self (3).
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
Thread IDs are guaranteed to be unique only within a process.
|
|
Packit |
7cfc04 |
(In all pthreads functions that accept a thread ID as an argument,
|
|
Packit |
7cfc04 |
that ID by definition refers to a thread in
|
|
Packit |
7cfc04 |
the same process as the caller.)
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
The system may reuse a thread ID after a terminated thread has been joined,
|
|
Packit |
7cfc04 |
or a detached thread has terminated.
|
|
Packit |
7cfc04 |
POSIX says: "If an application attempts to use a thread ID whose
|
|
Packit |
7cfc04 |
lifetime has ended, the behavior is undefined."
|
|
Packit |
7cfc04 |
.SS Thread-safe functions
|
|
Packit |
7cfc04 |
A thread-safe function is one that can be safely
|
|
Packit |
7cfc04 |
(i.e., it will deliver the same results regardless of whether it is)
|
|
Packit |
7cfc04 |
called from multiple threads at the same time.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
POSIX.1-2001 and POSIX.1-2008 require that all functions specified
|
|
Packit |
7cfc04 |
in the standard shall be thread-safe,
|
|
Packit |
7cfc04 |
except for the following functions:
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.in +4n
|
|
Packit |
7cfc04 |
.EX
|
|
Packit |
7cfc04 |
asctime()
|
|
Packit |
7cfc04 |
basename()
|
|
Packit |
7cfc04 |
catgets()
|
|
Packit |
7cfc04 |
crypt()
|
|
Packit |
7cfc04 |
ctermid() if passed a non-NULL argument
|
|
Packit |
7cfc04 |
ctime()
|
|
Packit |
7cfc04 |
dbm_clearerr()
|
|
Packit |
7cfc04 |
dbm_close()
|
|
Packit |
7cfc04 |
dbm_delete()
|
|
Packit |
7cfc04 |
dbm_error()
|
|
Packit |
7cfc04 |
dbm_fetch()
|
|
Packit |
7cfc04 |
dbm_firstkey()
|
|
Packit |
7cfc04 |
dbm_nextkey()
|
|
Packit |
7cfc04 |
dbm_open()
|
|
Packit |
7cfc04 |
dbm_store()
|
|
Packit |
7cfc04 |
dirname()
|
|
Packit |
7cfc04 |
dlerror()
|
|
Packit |
7cfc04 |
drand48()
|
|
Packit |
7cfc04 |
ecvt() [POSIX.1-2001 only (function removed in POSIX.1-2008)]
|
|
Packit |
7cfc04 |
encrypt()
|
|
Packit |
7cfc04 |
endgrent()
|
|
Packit |
7cfc04 |
endpwent()
|
|
Packit |
7cfc04 |
endutxent()
|
|
Packit |
7cfc04 |
fcvt() [POSIX.1-2001 only (function removed in POSIX.1-2008)]
|
|
Packit |
7cfc04 |
ftw()
|
|
Packit |
7cfc04 |
gcvt() [POSIX.1-2001 only (function removed in POSIX.1-2008)]
|
|
Packit |
7cfc04 |
getc_unlocked()
|
|
Packit |
7cfc04 |
getchar_unlocked()
|
|
Packit |
7cfc04 |
getdate()
|
|
Packit |
7cfc04 |
getenv()
|
|
Packit |
7cfc04 |
getgrent()
|
|
Packit |
7cfc04 |
getgrgid()
|
|
Packit |
7cfc04 |
getgrnam()
|
|
Packit |
7cfc04 |
gethostbyaddr() [POSIX.1-2001 only (function removed in POSIX.1-2008)]
|
|
Packit |
7cfc04 |
gethostbyname() [POSIX.1-2001 only (function removed in POSIX.1-2008)]
|
|
Packit |
7cfc04 |
gethostent()
|
|
Packit |
7cfc04 |
getlogin()
|
|
Packit |
7cfc04 |
getnetbyaddr()
|
|
Packit |
7cfc04 |
getnetbyname()
|
|
Packit |
7cfc04 |
getnetent()
|
|
Packit |
7cfc04 |
getopt()
|
|
Packit |
7cfc04 |
getprotobyname()
|
|
Packit |
7cfc04 |
getprotobynumber()
|
|
Packit |
7cfc04 |
getprotoent()
|
|
Packit |
7cfc04 |
getpwent()
|
|
Packit |
7cfc04 |
getpwnam()
|
|
Packit |
7cfc04 |
getpwuid()
|
|
Packit |
7cfc04 |
getservbyname()
|
|
Packit |
7cfc04 |
getservbyport()
|
|
Packit |
7cfc04 |
getservent()
|
|
Packit |
7cfc04 |
getutxent()
|
|
Packit |
7cfc04 |
getutxid()
|
|
Packit |
7cfc04 |
getutxline()
|
|
Packit |
7cfc04 |
gmtime()
|
|
Packit |
7cfc04 |
hcreate()
|
|
Packit |
7cfc04 |
hdestroy()
|
|
Packit |
7cfc04 |
hsearch()
|
|
Packit |
7cfc04 |
inet_ntoa()
|
|
Packit |
7cfc04 |
l64a()
|
|
Packit |
7cfc04 |
lgamma()
|
|
Packit |
7cfc04 |
lgammaf()
|
|
Packit |
7cfc04 |
lgammal()
|
|
Packit |
7cfc04 |
localeconv()
|
|
Packit |
7cfc04 |
localtime()
|
|
Packit |
7cfc04 |
lrand48()
|
|
Packit |
7cfc04 |
mrand48()
|
|
Packit |
7cfc04 |
nftw()
|
|
Packit |
7cfc04 |
nl_langinfo()
|
|
Packit |
7cfc04 |
ptsname()
|
|
Packit |
7cfc04 |
putc_unlocked()
|
|
Packit |
7cfc04 |
putchar_unlocked()
|
|
Packit |
7cfc04 |
putenv()
|
|
Packit |
7cfc04 |
pututxline()
|
|
Packit |
7cfc04 |
rand()
|
|
Packit |
7cfc04 |
readdir()
|
|
Packit |
7cfc04 |
setenv()
|
|
Packit |
7cfc04 |
setgrent()
|
|
Packit |
7cfc04 |
setkey()
|
|
Packit |
7cfc04 |
setpwent()
|
|
Packit |
7cfc04 |
setutxent()
|
|
Packit |
7cfc04 |
strerror()
|
|
Packit |
7cfc04 |
strsignal() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
strtok()
|
|
Packit |
7cfc04 |
system() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
tmpnam() if passed a non-NULL argument
|
|
Packit |
7cfc04 |
ttyname()
|
|
Packit |
7cfc04 |
unsetenv()
|
|
Packit |
7cfc04 |
wcrtomb() if its final argument is NULL
|
|
Packit |
7cfc04 |
wcsrtombs() if its final argument is NULL
|
|
Packit |
7cfc04 |
wcstombs()
|
|
Packit |
7cfc04 |
wctomb()
|
|
Packit |
7cfc04 |
.EE
|
|
Packit |
7cfc04 |
.in
|
|
Packit |
7cfc04 |
.SS Async-cancel-safe functions
|
|
Packit |
7cfc04 |
An async-cancel-safe function is one that can be safely called
|
|
Packit |
7cfc04 |
in an application where asynchronous cancelability is enabled (see
|
|
Packit |
7cfc04 |
.BR pthread_setcancelstate (3)).
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
Only the following functions are required to be async-cancel-safe by
|
|
Packit |
7cfc04 |
POSIX.1-2001 and POSIX.1-2008:
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.in +4n
|
|
Packit |
7cfc04 |
.EX
|
|
Packit |
7cfc04 |
pthread_cancel()
|
|
Packit |
7cfc04 |
pthread_setcancelstate()
|
|
Packit |
7cfc04 |
pthread_setcanceltype()
|
|
Packit |
7cfc04 |
.EE
|
|
Packit |
7cfc04 |
.in
|
|
Packit |
7cfc04 |
.SS Cancellation points
|
|
Packit |
7cfc04 |
POSIX.1 specifies that certain functions must,
|
|
Packit |
7cfc04 |
and certain other functions may, be cancellation points.
|
|
Packit |
7cfc04 |
If a thread is cancelable, its cancelability type is deferred,
|
|
Packit |
7cfc04 |
and a cancellation request is pending for the thread,
|
|
Packit |
7cfc04 |
then the thread is canceled when it calls a function
|
|
Packit |
7cfc04 |
that is a cancellation point.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
The following functions are required to be cancellation points by
|
|
Packit |
7cfc04 |
POSIX.1-2001 and/or POSIX.1-2008:
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.\" FIXME
|
|
Packit |
7cfc04 |
.\" Document the list of all functions that are cancellation points in glibc
|
|
Packit |
7cfc04 |
.in +4n
|
|
Packit |
7cfc04 |
.EX
|
|
Packit |
7cfc04 |
accept()
|
|
Packit |
7cfc04 |
aio_suspend()
|
|
Packit |
7cfc04 |
clock_nanosleep()
|
|
Packit |
7cfc04 |
close()
|
|
Packit |
7cfc04 |
connect()
|
|
Packit |
7cfc04 |
creat()
|
|
Packit |
7cfc04 |
fcntl() F_SETLKW
|
|
Packit |
7cfc04 |
fdatasync()
|
|
Packit |
7cfc04 |
fsync()
|
|
Packit |
7cfc04 |
getmsg()
|
|
Packit |
7cfc04 |
getpmsg()
|
|
Packit |
7cfc04 |
lockf() F_LOCK
|
|
Packit |
7cfc04 |
mq_receive()
|
|
Packit |
7cfc04 |
mq_send()
|
|
Packit |
7cfc04 |
mq_timedreceive()
|
|
Packit |
7cfc04 |
mq_timedsend()
|
|
Packit |
7cfc04 |
msgrcv()
|
|
Packit |
7cfc04 |
msgsnd()
|
|
Packit |
7cfc04 |
msync()
|
|
Packit |
7cfc04 |
nanosleep()
|
|
Packit |
7cfc04 |
open()
|
|
Packit |
7cfc04 |
openat() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
pause()
|
|
Packit |
7cfc04 |
poll()
|
|
Packit |
7cfc04 |
pread()
|
|
Packit |
7cfc04 |
pselect()
|
|
Packit |
7cfc04 |
pthread_cond_timedwait()
|
|
Packit |
7cfc04 |
pthread_cond_wait()
|
|
Packit |
7cfc04 |
pthread_join()
|
|
Packit |
7cfc04 |
pthread_testcancel()
|
|
Packit |
7cfc04 |
putmsg()
|
|
Packit |
7cfc04 |
putpmsg()
|
|
Packit |
7cfc04 |
pwrite()
|
|
Packit |
7cfc04 |
read()
|
|
Packit |
7cfc04 |
readv()
|
|
Packit |
7cfc04 |
recv()
|
|
Packit |
7cfc04 |
recvfrom()
|
|
Packit |
7cfc04 |
recvmsg()
|
|
Packit |
7cfc04 |
select()
|
|
Packit |
7cfc04 |
sem_timedwait()
|
|
Packit |
7cfc04 |
sem_wait()
|
|
Packit |
7cfc04 |
send()
|
|
Packit |
7cfc04 |
sendmsg()
|
|
Packit |
7cfc04 |
sendto()
|
|
Packit |
7cfc04 |
sigpause() [POSIX.1-2001 only (moves to "may" list in POSIX.1-2008)]
|
|
Packit |
7cfc04 |
sigsuspend()
|
|
Packit |
7cfc04 |
sigtimedwait()
|
|
Packit |
7cfc04 |
sigwait()
|
|
Packit |
7cfc04 |
sigwaitinfo()
|
|
Packit |
7cfc04 |
sleep()
|
|
Packit |
7cfc04 |
system()
|
|
Packit |
7cfc04 |
tcdrain()
|
|
Packit |
7cfc04 |
usleep() [POSIX.1-2001 only (function removed in POSIX.1-2008)]
|
|
Packit |
7cfc04 |
wait()
|
|
Packit |
7cfc04 |
waitid()
|
|
Packit |
7cfc04 |
waitpid()
|
|
Packit |
7cfc04 |
write()
|
|
Packit |
7cfc04 |
writev()
|
|
Packit |
7cfc04 |
.EE
|
|
Packit |
7cfc04 |
.in
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
The following functions may be cancellation points according to
|
|
Packit |
7cfc04 |
POSIX.1-2001 and/or POSIX.1-2008:
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.in +4n
|
|
Packit |
7cfc04 |
.EX
|
|
Packit |
7cfc04 |
access()
|
|
Packit |
7cfc04 |
asctime()
|
|
Packit |
7cfc04 |
asctime_r()
|
|
Packit |
7cfc04 |
catclose()
|
|
Packit |
7cfc04 |
catgets()
|
|
Packit |
7cfc04 |
catopen()
|
|
Packit |
7cfc04 |
chmod() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
chown() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
closedir()
|
|
Packit |
7cfc04 |
closelog()
|
|
Packit |
7cfc04 |
ctermid()
|
|
Packit |
7cfc04 |
ctime()
|
|
Packit |
7cfc04 |
ctime_r()
|
|
Packit |
7cfc04 |
dbm_close()
|
|
Packit |
7cfc04 |
dbm_delete()
|
|
Packit |
7cfc04 |
dbm_fetch()
|
|
Packit |
7cfc04 |
dbm_nextkey()
|
|
Packit |
7cfc04 |
dbm_open()
|
|
Packit |
7cfc04 |
dbm_store()
|
|
Packit |
7cfc04 |
dlclose()
|
|
Packit |
7cfc04 |
dlopen()
|
|
Packit |
7cfc04 |
dprintf() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
endgrent()
|
|
Packit |
7cfc04 |
endhostent()
|
|
Packit |
7cfc04 |
endnetent()
|
|
Packit |
7cfc04 |
endprotoent()
|
|
Packit |
7cfc04 |
endpwent()
|
|
Packit |
7cfc04 |
endservent()
|
|
Packit |
7cfc04 |
endutxent()
|
|
Packit |
7cfc04 |
faccessat() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
fchmod() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
fchmodat() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
fchown() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
fchownat() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
fclose()
|
|
Packit |
7cfc04 |
fcntl() (for any value of cmd argument)
|
|
Packit |
7cfc04 |
fflush()
|
|
Packit |
7cfc04 |
fgetc()
|
|
Packit |
7cfc04 |
fgetpos()
|
|
Packit |
7cfc04 |
fgets()
|
|
Packit |
7cfc04 |
fgetwc()
|
|
Packit |
7cfc04 |
fgetws()
|
|
Packit |
7cfc04 |
fmtmsg()
|
|
Packit |
7cfc04 |
fopen()
|
|
Packit |
7cfc04 |
fpathconf()
|
|
Packit |
7cfc04 |
fprintf()
|
|
Packit |
7cfc04 |
fputc()
|
|
Packit |
7cfc04 |
fputs()
|
|
Packit |
7cfc04 |
fputwc()
|
|
Packit |
7cfc04 |
fputws()
|
|
Packit |
7cfc04 |
fread()
|
|
Packit |
7cfc04 |
freopen()
|
|
Packit |
7cfc04 |
fscanf()
|
|
Packit |
7cfc04 |
fseek()
|
|
Packit |
7cfc04 |
fseeko()
|
|
Packit |
7cfc04 |
fsetpos()
|
|
Packit |
7cfc04 |
fstat()
|
|
Packit |
7cfc04 |
fstatat() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
ftell()
|
|
Packit |
7cfc04 |
ftello()
|
|
Packit |
7cfc04 |
ftw()
|
|
Packit |
7cfc04 |
futimens() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
fwprintf()
|
|
Packit |
7cfc04 |
fwrite()
|
|
Packit |
7cfc04 |
fwscanf()
|
|
Packit |
7cfc04 |
getaddrinfo()
|
|
Packit |
7cfc04 |
getc()
|
|
Packit |
7cfc04 |
getc_unlocked()
|
|
Packit |
7cfc04 |
getchar()
|
|
Packit |
7cfc04 |
getchar_unlocked()
|
|
Packit |
7cfc04 |
getcwd()
|
|
Packit |
7cfc04 |
getdate()
|
|
Packit |
7cfc04 |
getdelim() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
getgrent()
|
|
Packit |
7cfc04 |
getgrgid()
|
|
Packit |
7cfc04 |
getgrgid_r()
|
|
Packit |
7cfc04 |
getgrnam()
|
|
Packit |
7cfc04 |
getgrnam_r()
|
|
Packit |
7cfc04 |
gethostbyaddr() [SUSv3 only (function removed in POSIX.1-2008)]
|
|
Packit |
7cfc04 |
gethostbyname() [SUSv3 only (function removed in POSIX.1-2008)]
|
|
Packit |
7cfc04 |
gethostent()
|
|
Packit |
7cfc04 |
gethostid()
|
|
Packit |
7cfc04 |
gethostname()
|
|
Packit |
7cfc04 |
getline() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
getlogin()
|
|
Packit |
7cfc04 |
getlogin_r()
|
|
Packit |
7cfc04 |
getnameinfo()
|
|
Packit |
7cfc04 |
getnetbyaddr()
|
|
Packit |
7cfc04 |
getnetbyname()
|
|
Packit |
7cfc04 |
getnetent()
|
|
Packit |
7cfc04 |
getopt() (if opterr is nonzero)
|
|
Packit |
7cfc04 |
getprotobyname()
|
|
Packit |
7cfc04 |
getprotobynumber()
|
|
Packit |
7cfc04 |
getprotoent()
|
|
Packit |
7cfc04 |
getpwent()
|
|
Packit |
7cfc04 |
getpwnam()
|
|
Packit |
7cfc04 |
getpwnam_r()
|
|
Packit |
7cfc04 |
getpwuid()
|
|
Packit |
7cfc04 |
getpwuid_r()
|
|
Packit |
7cfc04 |
gets()
|
|
Packit |
7cfc04 |
getservbyname()
|
|
Packit |
7cfc04 |
getservbyport()
|
|
Packit |
7cfc04 |
getservent()
|
|
Packit |
7cfc04 |
getutxent()
|
|
Packit |
7cfc04 |
getutxid()
|
|
Packit |
7cfc04 |
getutxline()
|
|
Packit |
7cfc04 |
getwc()
|
|
Packit |
7cfc04 |
getwchar()
|
|
Packit |
7cfc04 |
getwd() [SUSv3 only (function removed in POSIX.1-2008)]
|
|
Packit |
7cfc04 |
glob()
|
|
Packit |
7cfc04 |
iconv_close()
|
|
Packit |
7cfc04 |
iconv_open()
|
|
Packit |
7cfc04 |
ioctl()
|
|
Packit |
7cfc04 |
link()
|
|
Packit |
7cfc04 |
linkat() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
lio_listio() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
localtime()
|
|
Packit |
7cfc04 |
localtime_r()
|
|
Packit |
7cfc04 |
lockf() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
lseek()
|
|
Packit |
7cfc04 |
lstat()
|
|
Packit |
7cfc04 |
mkdir() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
mkdirat() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
mkdtemp() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
mkfifo() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
mkfifoat() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
mknod() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
mknodat() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
mkstemp()
|
|
Packit |
7cfc04 |
mktime()
|
|
Packit |
7cfc04 |
nftw()
|
|
Packit |
7cfc04 |
opendir()
|
|
Packit |
7cfc04 |
openlog()
|
|
Packit |
7cfc04 |
pathconf()
|
|
Packit |
7cfc04 |
pclose()
|
|
Packit |
7cfc04 |
perror()
|
|
Packit |
7cfc04 |
popen()
|
|
Packit |
7cfc04 |
posix_fadvise()
|
|
Packit |
7cfc04 |
posix_fallocate()
|
|
Packit |
7cfc04 |
posix_madvise()
|
|
Packit |
7cfc04 |
posix_openpt()
|
|
Packit |
7cfc04 |
posix_spawn()
|
|
Packit |
7cfc04 |
posix_spawnp()
|
|
Packit |
7cfc04 |
posix_trace_clear()
|
|
Packit |
7cfc04 |
posix_trace_close()
|
|
Packit |
7cfc04 |
posix_trace_create()
|
|
Packit |
7cfc04 |
posix_trace_create_withlog()
|
|
Packit |
7cfc04 |
posix_trace_eventtypelist_getnext_id()
|
|
Packit |
7cfc04 |
posix_trace_eventtypelist_rewind()
|
|
Packit |
7cfc04 |
posix_trace_flush()
|
|
Packit |
7cfc04 |
posix_trace_get_attr()
|
|
Packit |
7cfc04 |
posix_trace_get_filter()
|
|
Packit |
7cfc04 |
posix_trace_get_status()
|
|
Packit |
7cfc04 |
posix_trace_getnext_event()
|
|
Packit |
7cfc04 |
posix_trace_open()
|
|
Packit |
7cfc04 |
posix_trace_rewind()
|
|
Packit |
7cfc04 |
posix_trace_set_filter()
|
|
Packit |
7cfc04 |
posix_trace_shutdown()
|
|
Packit |
7cfc04 |
posix_trace_timedgetnext_event()
|
|
Packit |
7cfc04 |
posix_typed_mem_open()
|
|
Packit |
7cfc04 |
printf()
|
|
Packit |
7cfc04 |
psiginfo() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
psignal() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
pthread_rwlock_rdlock()
|
|
Packit |
7cfc04 |
pthread_rwlock_timedrdlock()
|
|
Packit |
7cfc04 |
pthread_rwlock_timedwrlock()
|
|
Packit |
7cfc04 |
pthread_rwlock_wrlock()
|
|
Packit |
7cfc04 |
putc()
|
|
Packit |
7cfc04 |
putc_unlocked()
|
|
Packit |
7cfc04 |
putchar()
|
|
Packit |
7cfc04 |
putchar_unlocked()
|
|
Packit |
7cfc04 |
puts()
|
|
Packit |
7cfc04 |
pututxline()
|
|
Packit |
7cfc04 |
putwc()
|
|
Packit |
7cfc04 |
putwchar()
|
|
Packit |
7cfc04 |
readdir()
|
|
Packit |
7cfc04 |
readdir_r()
|
|
Packit |
7cfc04 |
readlink() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
readlinkat() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
remove()
|
|
Packit |
7cfc04 |
rename()
|
|
Packit |
7cfc04 |
renameat() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
rewind()
|
|
Packit |
7cfc04 |
rewinddir()
|
|
Packit |
7cfc04 |
scandir() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
scanf()
|
|
Packit |
7cfc04 |
seekdir()
|
|
Packit |
7cfc04 |
semop()
|
|
Packit |
7cfc04 |
setgrent()
|
|
Packit |
7cfc04 |
sethostent()
|
|
Packit |
7cfc04 |
setnetent()
|
|
Packit |
7cfc04 |
setprotoent()
|
|
Packit |
7cfc04 |
setpwent()
|
|
Packit |
7cfc04 |
setservent()
|
|
Packit |
7cfc04 |
setutxent()
|
|
Packit |
7cfc04 |
sigpause() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
stat()
|
|
Packit |
7cfc04 |
strerror()
|
|
Packit |
7cfc04 |
strerror_r()
|
|
Packit |
7cfc04 |
strftime()
|
|
Packit |
7cfc04 |
symlink()
|
|
Packit |
7cfc04 |
symlinkat() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
sync()
|
|
Packit |
7cfc04 |
syslog()
|
|
Packit |
7cfc04 |
tmpfile()
|
|
Packit |
7cfc04 |
tmpnam()
|
|
Packit |
7cfc04 |
ttyname()
|
|
Packit |
7cfc04 |
ttyname_r()
|
|
Packit |
7cfc04 |
tzset()
|
|
Packit |
7cfc04 |
ungetc()
|
|
Packit |
7cfc04 |
ungetwc()
|
|
Packit |
7cfc04 |
unlink()
|
|
Packit |
7cfc04 |
unlinkat() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
utime() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
utimensat() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
utimes() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
vdprintf() [Added in POSIX.1-2008]
|
|
Packit |
7cfc04 |
vfprintf()
|
|
Packit |
7cfc04 |
vfwprintf()
|
|
Packit |
7cfc04 |
vprintf()
|
|
Packit |
7cfc04 |
vwprintf()
|
|
Packit |
7cfc04 |
wcsftime()
|
|
Packit |
7cfc04 |
wordexp()
|
|
Packit |
7cfc04 |
wprintf()
|
|
Packit |
7cfc04 |
wscanf()
|
|
Packit |
7cfc04 |
.EE
|
|
Packit |
7cfc04 |
.in
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
An implementation may also mark other functions
|
|
Packit |
7cfc04 |
not specified in the standard as cancellation points.
|
|
Packit |
7cfc04 |
In particular, an implementation is likely to mark
|
|
Packit |
7cfc04 |
any nonstandard function that may block as a cancellation point.
|
|
Packit |
7cfc04 |
(This includes most functions that can touch files.)
|
|
Packit |
7cfc04 |
.\" So, scanning "cancellation point" comments in the glibc 2.8 header
|
|
Packit |
7cfc04 |
.\" files, it looks as though at least the following nonstandard
|
|
Packit |
7cfc04 |
.\" functions are cancellation points:
|
|
Packit |
7cfc04 |
.\" endnetgrent
|
|
Packit |
7cfc04 |
.\" endspent
|
|
Packit |
7cfc04 |
.\" epoll_pwait
|
|
Packit |
7cfc04 |
.\" epoll_wait
|
|
Packit |
7cfc04 |
.\" fcloseall
|
|
Packit |
7cfc04 |
.\" fdopendir
|
|
Packit |
7cfc04 |
.\" fflush_unlocked
|
|
Packit |
7cfc04 |
.\" fgetc_unlocked
|
|
Packit |
7cfc04 |
.\" fgetgrent
|
|
Packit |
7cfc04 |
.\" fgetgrent_r
|
|
Packit |
7cfc04 |
.\" fgetpwent
|
|
Packit |
7cfc04 |
.\" fgetpwent_r
|
|
Packit |
7cfc04 |
.\" fgets_unlocked
|
|
Packit |
7cfc04 |
.\" fgetspent
|
|
Packit |
7cfc04 |
.\" fgetspent_r
|
|
Packit |
7cfc04 |
.\" fgetwc_unlocked
|
|
Packit |
7cfc04 |
.\" fgetws_unlocked
|
|
Packit |
7cfc04 |
.\" fputc_unlocked
|
|
Packit |
7cfc04 |
.\" fputs_unlocked
|
|
Packit |
7cfc04 |
.\" fputwc_unlocked
|
|
Packit |
7cfc04 |
.\" fputws_unlocked
|
|
Packit |
7cfc04 |
.\" fread_unlocked
|
|
Packit |
7cfc04 |
.\" fwrite_unlocked
|
|
Packit |
7cfc04 |
.\" gai_suspend
|
|
Packit |
7cfc04 |
.\" getaddrinfo_a
|
|
Packit |
7cfc04 |
.\" getdate_r
|
|
Packit |
7cfc04 |
.\" getgrent_r
|
|
Packit |
7cfc04 |
.\" getgrouplist
|
|
Packit |
7cfc04 |
.\" gethostbyaddr_r
|
|
Packit |
7cfc04 |
.\" gethostbyname2
|
|
Packit |
7cfc04 |
.\" gethostbyname2_r
|
|
Packit |
7cfc04 |
.\" gethostbyname_r
|
|
Packit |
7cfc04 |
.\" gethostent_r
|
|
Packit |
7cfc04 |
.\" getnetbyaddr_r
|
|
Packit |
7cfc04 |
.\" getnetbyname_r
|
|
Packit |
7cfc04 |
.\" getnetent_r
|
|
Packit |
7cfc04 |
.\" getnetgrent
|
|
Packit |
7cfc04 |
.\" getnetgrent_r
|
|
Packit |
7cfc04 |
.\" getprotobyname_r
|
|
Packit |
7cfc04 |
.\" getprotobynumber_r
|
|
Packit |
7cfc04 |
.\" getprotoent_r
|
|
Packit |
7cfc04 |
.\" getpw
|
|
Packit |
7cfc04 |
.\" getpwent_r
|
|
Packit |
7cfc04 |
.\" getservbyname_r
|
|
Packit |
7cfc04 |
.\" getservbyport_r
|
|
Packit |
7cfc04 |
.\" getservent_r
|
|
Packit |
7cfc04 |
.\" getspent
|
|
Packit |
7cfc04 |
.\" getspent_r
|
|
Packit |
7cfc04 |
.\" getspnam
|
|
Packit |
7cfc04 |
.\" getspnam_r
|
|
Packit |
7cfc04 |
.\" getutmp
|
|
Packit |
7cfc04 |
.\" getutmpx
|
|
Packit |
7cfc04 |
.\" getw
|
|
Packit |
7cfc04 |
.\" getwc_unlocked
|
|
Packit |
7cfc04 |
.\" getwchar_unlocked
|
|
Packit |
7cfc04 |
.\" initgroups
|
|
Packit |
7cfc04 |
.\" innetgr
|
|
Packit |
7cfc04 |
.\" mkostemp
|
|
Packit |
7cfc04 |
.\" mkostemp64
|
|
Packit |
7cfc04 |
.\" mkstemp64
|
|
Packit |
7cfc04 |
.\" ppoll
|
|
Packit |
7cfc04 |
.\" pthread_timedjoin_np
|
|
Packit |
7cfc04 |
.\" putgrent
|
|
Packit |
7cfc04 |
.\" putpwent
|
|
Packit |
7cfc04 |
.\" putspent
|
|
Packit |
7cfc04 |
.\" putw
|
|
Packit |
7cfc04 |
.\" putwc_unlocked
|
|
Packit |
7cfc04 |
.\" putwchar_unlocked
|
|
Packit |
7cfc04 |
.\" rcmd
|
|
Packit |
7cfc04 |
.\" rcmd_af
|
|
Packit |
7cfc04 |
.\" rexec
|
|
Packit |
7cfc04 |
.\" rexec_af
|
|
Packit |
7cfc04 |
.\" rresvport
|
|
Packit |
7cfc04 |
.\" rresvport_af
|
|
Packit |
7cfc04 |
.\" ruserok
|
|
Packit |
7cfc04 |
.\" ruserok_af
|
|
Packit |
7cfc04 |
.\" setnetgrent
|
|
Packit |
7cfc04 |
.\" setspent
|
|
Packit |
7cfc04 |
.\" sgetspent
|
|
Packit |
7cfc04 |
.\" sgetspent_r
|
|
Packit |
7cfc04 |
.\" updwtmpx
|
|
Packit |
7cfc04 |
.\" utmpxname
|
|
Packit |
7cfc04 |
.\" vfscanf
|
|
Packit |
7cfc04 |
.\" vfwscanf
|
|
Packit |
7cfc04 |
.\" vscanf
|
|
Packit |
7cfc04 |
.\" vsyslog
|
|
Packit |
7cfc04 |
.\" vwscanf
|
|
Packit |
7cfc04 |
.SS Compiling on Linux
|
|
Packit |
7cfc04 |
On Linux, programs that use the Pthreads API should be compiled using
|
|
Packit |
7cfc04 |
.IR "cc \-pthread" .
|
|
Packit |
7cfc04 |
.SS Linux implementations of POSIX threads
|
|
Packit |
7cfc04 |
Over time, two threading implementations have been provided by
|
|
Packit |
7cfc04 |
the GNU C library on Linux:
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.B LinuxThreads
|
|
Packit |
7cfc04 |
This is the original Pthreads implementation.
|
|
Packit |
7cfc04 |
Since glibc 2.4, this implementation is no longer supported.
|
|
Packit |
7cfc04 |
.TP
|
|
Packit |
7cfc04 |
.BR NPTL " (Native POSIX Threads Library)"
|
|
Packit |
7cfc04 |
This is the modern Pthreads implementation.
|
|
Packit |
7cfc04 |
By comparison with LinuxThreads, NPTL provides closer conformance to
|
|
Packit |
7cfc04 |
the requirements of the POSIX.1 specification and better performance
|
|
Packit |
7cfc04 |
when creating large numbers of threads.
|
|
Packit |
7cfc04 |
NPTL is available since glibc 2.3.2,
|
|
Packit |
7cfc04 |
and requires features that are present in the Linux 2.6 kernel.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
Both of these are so-called 1:1 implementations, meaning that each
|
|
Packit |
7cfc04 |
thread maps to a kernel scheduling entity.
|
|
Packit |
7cfc04 |
Both threading implementations employ the Linux
|
|
Packit |
7cfc04 |
.BR clone (2)
|
|
Packit |
7cfc04 |
system call.
|
|
Packit |
7cfc04 |
In NPTL, thread synchronization primitives (mutexes,
|
|
Packit |
7cfc04 |
thread joining, and so on) are implemented using the Linux
|
|
Packit |
7cfc04 |
.BR futex (2)
|
|
Packit |
7cfc04 |
system call.
|
|
Packit |
7cfc04 |
.SS LinuxThreads
|
|
Packit |
7cfc04 |
The notable features of this implementation are the following:
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
In addition to the main (initial) thread,
|
|
Packit |
7cfc04 |
and the threads that the program creates using
|
|
Packit |
7cfc04 |
.BR pthread_create (3),
|
|
Packit |
7cfc04 |
the implementation creates a "manager" thread.
|
|
Packit |
7cfc04 |
This thread handles thread creation and termination.
|
|
Packit |
7cfc04 |
(Problems can result if this thread is inadvertently killed.)
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
Signals are used internally by the implementation.
|
|
Packit |
7cfc04 |
On Linux 2.2 and later, the first three real-time signals are used
|
|
Packit |
7cfc04 |
(see also
|
|
Packit |
7cfc04 |
.BR signal (7)).
|
|
Packit |
7cfc04 |
On older Linux kernels,
|
|
Packit |
7cfc04 |
.B SIGUSR1
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
.B SIGUSR2
|
|
Packit |
7cfc04 |
are used.
|
|
Packit |
7cfc04 |
Applications must avoid the use of whichever set of signals is
|
|
Packit |
7cfc04 |
employed by the implementation.
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
Threads do not share process IDs.
|
|
Packit |
7cfc04 |
(In effect, LinuxThreads threads are implemented as processes which share
|
|
Packit |
7cfc04 |
more information than usual, but which do not share a common process ID.)
|
|
Packit |
7cfc04 |
LinuxThreads threads (including the manager thread)
|
|
Packit |
7cfc04 |
are visible as separate processes using
|
|
Packit |
7cfc04 |
.BR ps (1).
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
The LinuxThreads implementation deviates from the POSIX.1
|
|
Packit |
7cfc04 |
specification in a number of ways, including the following:
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
Calls to
|
|
Packit |
7cfc04 |
.BR getpid (2)
|
|
Packit |
7cfc04 |
return a different value in each thread.
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
Calls to
|
|
Packit |
7cfc04 |
.BR getppid (2)
|
|
Packit |
7cfc04 |
in threads other than the main thread return the process ID of the
|
|
Packit |
7cfc04 |
manager thread; instead
|
|
Packit |
7cfc04 |
.BR getppid (2)
|
|
Packit |
7cfc04 |
in these threads should return the same value as
|
|
Packit |
7cfc04 |
.BR getppid (2)
|
|
Packit |
7cfc04 |
in the main thread.
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
When one thread creates a new child process using
|
|
Packit |
7cfc04 |
.BR fork (2),
|
|
Packit |
7cfc04 |
any thread should be able to
|
|
Packit |
7cfc04 |
.BR wait (2)
|
|
Packit |
7cfc04 |
on the child.
|
|
Packit |
7cfc04 |
However, the implementation allows only the thread that
|
|
Packit |
7cfc04 |
created the child to
|
|
Packit |
7cfc04 |
.BR wait (2)
|
|
Packit |
7cfc04 |
on it.
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
When a thread calls
|
|
Packit |
7cfc04 |
.BR execve (2),
|
|
Packit |
7cfc04 |
all other threads are terminated (as required by POSIX.1).
|
|
Packit |
7cfc04 |
However, the resulting process has the same PID as the thread that called
|
|
Packit |
7cfc04 |
.BR execve (2):
|
|
Packit |
7cfc04 |
it should have the same PID as the main thread.
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
Threads do not share user and group IDs.
|
|
Packit |
7cfc04 |
This can cause complications with set-user-ID programs and
|
|
Packit |
7cfc04 |
can cause failures in Pthreads functions if an application
|
|
Packit |
7cfc04 |
changes its credentials using
|
|
Packit |
7cfc04 |
.BR seteuid (2)
|
|
Packit |
7cfc04 |
or similar.
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
Threads do not share a common session ID and process group ID.
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
Threads do not share record locks created using
|
|
Packit |
7cfc04 |
.BR fcntl (2).
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
The information returned by
|
|
Packit |
7cfc04 |
.BR times (2)
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
.BR getrusage (2)
|
|
Packit |
7cfc04 |
is per-thread rather than process-wide.
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
Threads do not share semaphore undo values (see
|
|
Packit |
7cfc04 |
.BR semop (2)).
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
Threads do not share interval timers.
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
Threads do not share a common nice value.
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
POSIX.1 distinguishes the notions of signals that are directed
|
|
Packit |
7cfc04 |
to the process as a whole and signals that are directed to individual
|
|
Packit |
7cfc04 |
threads.
|
|
Packit |
7cfc04 |
According to POSIX.1, a process-directed signal (sent using
|
|
Packit |
7cfc04 |
.BR kill (2),
|
|
Packit |
7cfc04 |
for example) should be handled by a single,
|
|
Packit |
7cfc04 |
arbitrarily selected thread within the process.
|
|
Packit |
7cfc04 |
LinuxThreads does not support the notion of process-directed signals:
|
|
Packit |
7cfc04 |
signals may be sent only to specific threads.
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
Threads have distinct alternate signal stack settings.
|
|
Packit |
7cfc04 |
However, a new thread's alternate signal stack settings
|
|
Packit |
7cfc04 |
are copied from the thread that created it, so that
|
|
Packit |
7cfc04 |
the threads initially share an alternate signal stack.
|
|
Packit |
7cfc04 |
(A new thread should start with no alternate signal stack defined.
|
|
Packit |
7cfc04 |
If two threads handle signals on their shared alternate signal
|
|
Packit |
7cfc04 |
stack at the same time, unpredictable program failures are
|
|
Packit |
7cfc04 |
likely to occur.)
|
|
Packit |
7cfc04 |
.SS NPTL
|
|
Packit |
7cfc04 |
With NPTL, all of the threads in a process are placed
|
|
Packit |
7cfc04 |
in the same thread group;
|
|
Packit |
7cfc04 |
all members of a thread group share the same PID.
|
|
Packit |
7cfc04 |
NPTL does not employ a manager thread.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
NPTL makes internal use of the first two real-time signals;
|
|
Packit |
7cfc04 |
these signals cannot be used in applications.
|
|
Packit |
7cfc04 |
See
|
|
Packit |
7cfc04 |
.BR nptl (7)
|
|
Packit |
7cfc04 |
for further details.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
NPTL still has at least one nonconformance with POSIX.1:
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
Threads do not share a common nice value.
|
|
Packit |
7cfc04 |
.\" FIXME . bug report filed for NPTL nice nonconformance
|
|
Packit |
7cfc04 |
.\" http://bugzilla.kernel.org/show_bug.cgi?id=6258
|
|
Packit |
7cfc04 |
.\" Sep 08: there is a patch by Denys Vlasenko to address this
|
|
Packit |
7cfc04 |
.\" "make setpriority POSIX compliant; introduce PRIO_THREAD extension"
|
|
Packit |
7cfc04 |
.\" Monitor this to see if it makes it into mainline.
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
Some NPTL nonconformances occur only with older kernels:
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
The information returned by
|
|
Packit |
7cfc04 |
.BR times (2)
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
.BR getrusage (2)
|
|
Packit |
7cfc04 |
is per-thread rather than process-wide (fixed in kernel 2.6.9).
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
Threads do not share resource limits (fixed in kernel 2.6.10).
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
Threads do not share interval timers (fixed in kernel 2.6.12).
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
Only the main thread is permitted to start a new session using
|
|
Packit |
7cfc04 |
.BR setsid (2)
|
|
Packit |
7cfc04 |
(fixed in kernel 2.6.16).
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
Only the main thread is permitted to make the process into a
|
|
Packit |
7cfc04 |
process group leader using
|
|
Packit |
7cfc04 |
.BR setpgid (2)
|
|
Packit |
7cfc04 |
(fixed in kernel 2.6.16).
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
Threads have distinct alternate signal stack settings.
|
|
Packit |
7cfc04 |
However, a new thread's alternate signal stack settings
|
|
Packit |
7cfc04 |
are copied from the thread that created it, so that
|
|
Packit |
7cfc04 |
the threads initially share an alternate signal stack
|
|
Packit |
7cfc04 |
(fixed in kernel 2.6.16).
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
Note the following further points about the NPTL implementation:
|
|
Packit |
7cfc04 |
.IP \- 3
|
|
Packit |
7cfc04 |
If the stack size soft resource limit (see the description of
|
|
Packit |
7cfc04 |
.B RLIMIT_STACK
|
|
Packit |
7cfc04 |
in
|
|
Packit |
7cfc04 |
.BR setrlimit (2))
|
|
Packit |
7cfc04 |
is set to a value other than
|
|
Packit |
7cfc04 |
.IR unlimited ,
|
|
Packit |
7cfc04 |
then this value defines the default stack size for new threads.
|
|
Packit |
7cfc04 |
To be effective, this limit must be set before the program
|
|
Packit |
7cfc04 |
is executed, perhaps using the
|
|
Packit |
7cfc04 |
.I ulimit -s
|
|
Packit |
7cfc04 |
shell built-in command
|
|
Packit |
7cfc04 |
.RI ( "limit stacksize"
|
|
Packit |
7cfc04 |
in the C shell).
|
|
Packit |
7cfc04 |
.SS Determining the threading implementation
|
|
Packit |
7cfc04 |
Since glibc 2.3.2, the
|
|
Packit |
7cfc04 |
.BR getconf (1)
|
|
Packit |
7cfc04 |
command can be used to determine
|
|
Packit |
7cfc04 |
the system's threading implementation, for example:
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.in +4n
|
|
Packit |
7cfc04 |
.EX
|
|
Packit |
7cfc04 |
bash$ getconf GNU_LIBPTHREAD_VERSION
|
|
Packit |
7cfc04 |
NPTL 2.3.4
|
|
Packit |
7cfc04 |
.EE
|
|
Packit |
7cfc04 |
.in
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
With older glibc versions, a command such as the following should
|
|
Packit |
7cfc04 |
be sufficient to determine the default threading implementation:
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.in +4n
|
|
Packit |
7cfc04 |
.EX
|
|
Packit |
7cfc04 |
bash$ $( ldd /bin/ls | grep libc.so | awk \(aq{print $3}\(aq ) | \\
|
|
Packit |
7cfc04 |
egrep \-i \(aqthreads|nptl\(aq
|
|
Packit |
7cfc04 |
Native POSIX Threads Library by Ulrich Drepper et al
|
|
Packit |
7cfc04 |
.EE
|
|
Packit |
7cfc04 |
.in
|
|
Packit |
7cfc04 |
.SS Selecting the threading implementation: LD_ASSUME_KERNEL
|
|
Packit |
7cfc04 |
On systems with a glibc that supports both LinuxThreads and NPTL
|
|
Packit |
7cfc04 |
(i.e., glibc 2.3.\fIx\fP), the
|
|
Packit |
7cfc04 |
.B LD_ASSUME_KERNEL
|
|
Packit |
7cfc04 |
environment variable can be used to override
|
|
Packit |
7cfc04 |
the dynamic linker's default choice of threading implementation.
|
|
Packit |
7cfc04 |
This variable tells the dynamic linker to assume that it is
|
|
Packit |
7cfc04 |
running on top of a particular kernel version.
|
|
Packit |
7cfc04 |
By specifying a kernel version that does not
|
|
Packit |
7cfc04 |
provide the support required by NPTL, we can force the use
|
|
Packit |
7cfc04 |
of LinuxThreads.
|
|
Packit |
7cfc04 |
(The most likely reason for doing this is to run a
|
|
Packit |
7cfc04 |
(broken) application that depends on some nonconformant behavior
|
|
Packit |
7cfc04 |
in LinuxThreads.)
|
|
Packit |
7cfc04 |
For example:
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
.in +4n
|
|
Packit |
7cfc04 |
.EX
|
|
Packit |
7cfc04 |
bash$ $( LD_ASSUME_KERNEL=2.2.5 ldd /bin/ls | grep libc.so | \\
|
|
Packit |
7cfc04 |
awk \(aq{print $3}\(aq ) | egrep \-i \(aqthreads|nptl\(aq
|
|
Packit |
7cfc04 |
linuxthreads-0.10 by Xavier Leroy
|
|
Packit |
7cfc04 |
.EE
|
|
Packit |
7cfc04 |
.in
|
|
Packit |
7cfc04 |
.SH SEE ALSO
|
|
Packit |
7cfc04 |
.ad l
|
|
Packit |
7cfc04 |
.nh
|
|
Packit |
7cfc04 |
.BR clone (2),
|
|
Packit |
7cfc04 |
.BR fork (2),
|
|
Packit |
7cfc04 |
.BR futex (2),
|
|
Packit |
7cfc04 |
.BR gettid (2),
|
|
Packit |
7cfc04 |
.BR proc (5),
|
|
Packit |
7cfc04 |
.BR attributes (7),
|
|
Packit |
7cfc04 |
.BR futex (7),
|
|
Packit |
7cfc04 |
.BR nptl (7),
|
|
Packit |
7cfc04 |
.BR sigevent (7),
|
|
Packit |
7cfc04 |
.BR signal (7)
|
|
Packit |
7cfc04 |
.PP
|
|
Packit |
7cfc04 |
Various Pthreads manual pages, for example:
|
|
Packit |
7cfc04 |
.BR pthread_atfork (3),
|
|
Packit |
7cfc04 |
.BR pthread_attr_init (3),
|
|
Packit |
7cfc04 |
.BR pthread_cancel (3),
|
|
Packit |
7cfc04 |
.BR pthread_cleanup_push (3),
|
|
Packit |
7cfc04 |
.BR pthread_cond_signal (3),
|
|
Packit |
7cfc04 |
.BR pthread_cond_wait (3),
|
|
Packit |
7cfc04 |
.BR pthread_create (3),
|
|
Packit |
7cfc04 |
.BR pthread_detach (3),
|
|
Packit |
7cfc04 |
.BR pthread_equal (3),
|
|
Packit |
7cfc04 |
.BR pthread_exit (3),
|
|
Packit |
7cfc04 |
.BR pthread_key_create (3),
|
|
Packit |
7cfc04 |
.BR pthread_kill (3),
|
|
Packit |
7cfc04 |
.BR pthread_mutex_lock (3),
|
|
Packit |
7cfc04 |
.BR pthread_mutex_unlock (3),
|
|
Packit |
7cfc04 |
.BR pthread_mutexattr_destroy (3),
|
|
Packit |
7cfc04 |
.BR pthread_mutexattr_init (3),
|
|
Packit |
7cfc04 |
.BR pthread_once (3),
|
|
Packit |
7cfc04 |
.BR pthread_spin_init (3),
|
|
Packit |
7cfc04 |
.BR pthread_spin_lock (3),
|
|
Packit |
7cfc04 |
.BR pthread_rwlockattr_setkind_np (3),
|
|
Packit |
7cfc04 |
.BR pthread_setcancelstate (3),
|
|
Packit |
7cfc04 |
.BR pthread_setcanceltype (3),
|
|
Packit |
7cfc04 |
.BR pthread_setspecific (3),
|
|
Packit |
7cfc04 |
.BR pthread_sigmask (3),
|
|
Packit |
7cfc04 |
.BR pthread_sigqueue (3),
|
|
Packit |
7cfc04 |
and
|
|
Packit |
7cfc04 |
.BR pthread_testcancel (3)
|
|
Packit |
7cfc04 |
.SH COLOPHON
|
|
Packit |
7cfc04 |
This page is part of release 4.15 of the Linux
|
|
Packit |
7cfc04 |
.I man-pages
|
|
Packit |
7cfc04 |
project.
|
|
Packit |
7cfc04 |
A description of the project,
|
|
Packit |
7cfc04 |
information about reporting bugs,
|
|
Packit |
7cfc04 |
and the latest version of this page,
|
|
Packit |
7cfc04 |
can be found at
|
|
Packit |
7cfc04 |
\%https://www.kernel.org/doc/man\-pages/.
|