POSIX.1 はスレッド間でどのような属性を共有するかについても定めている (つまり、これらの属性はスレッド単位ではなくプロセス全体で共通である):
スタックについても、POSIX.1 はどのような属性が 個々のスレッドで独立に管理されるかを規定している:
以下の Linux 特有の機能もスレッド単位である:
Thread IDs are guaranteed to be unique only within a process. (In all pthreads functions that accept a thread ID as an argument, that ID by definition refers to a thread in the same process as the caller.)
The system may reuse a thread ID after a terminated thread has been joined, or a detached thread has terminated. POSIX says: "If an application attempts to use a thread ID whose lifetime has ended, the behavior is undefined."
POSIX.1-2001 と POSIX.1-2008では、一部の例外を除き、 標準で規定されている全ての関数がスレッドセーフであることを要求している。 以下の関数が例外である。
asctime() basename() catgets() crypt() ctermid() (NULL でない引数を渡された場合) ctime() dbm_clearerr() dbm_close() dbm_delete() dbm_error() dbm_fetch() dbm_firstkey() dbm_nextkey() dbm_open() dbm_store() dirname() dlerror() drand48() ecvt() [POSIX.1-2001 のみ (POSIX.1-2008 で削除された)] encrypt() endgrent() endpwent() endutxent() fcvt() [POSIX.1-2001 のみ (POSIX.1-2008 で削除された)] ftw() gcvt() [POSIX.1-2001 のみ (POSIX.1-2008 で削除された)] getc_unlocked() getchar_unlocked() getdate() getenv() getgrent() getgrgid() getgrnam() gethostbyaddr() [POSIX.1-2001 のみ (POSIX.1-2008 で削除された)] gethostbyname() [POSIX.1-2001 のみ (POSIX.1-2008 で削除された)] gethostent() getlogin() getnetbyaddr() getnetbyname() getnetent() getopt() getprotobyname() getprotobynumber() getprotoent() getpwent() getpwnam() getpwuid() getservbyname() getservbyport() getservent() getutxent() getutxid() getutxline() gmtime() hcreate() hdestroy() hsearch() inet_ntoa() l64a() lgamma() lgammaf() lgammal() localeconv() localtime() lrand48() mrand48() nftw() nl_langinfo() ptsname() putc_unlocked() putchar_unlocked() putenv() pututxline() rand() readdir() setenv() setgrent() setkey() setpwent() setutxent() strerror() strsignal() [POSIX.1-2008 で追加された] strtok() system() [POSIX.1-2008 で追加された] tmpnam() (NULL でない引数を渡された場合) ttyname() unsetenv() wcrtomb() (最後の引数が NULL の場合) wcsrtombs() (最後の引数が NULL の場合) wcstombs() wctomb()
以下の関数だけが、POSIX.1-2001 と POSIX.1-2008 で async-cancel-safe で なければならないとされている。
pthread_cancel() pthread_setcancelstate() pthread_setcanceltype()
The following functions are required to be cancelation points by POSIX.1-2001 and/or POSIX.1-2008:
accept() aio_suspend() clock_nanosleep() close() connect() creat() fcntl() F_SETLKW fdatasync() fsync() getmsg() getpmsg() lockf() F_LOCK mq_receive() mq_send() mq_timedreceive() mq_timedsend() msgrcv() msgsnd() msync() nanosleep() open() openat() [POSIX.1-2008 で追加された] pause() poll() pread() pselect() pthread_cond_timedwait() pthread_cond_wait() pthread_join() pthread_testcancel() putmsg() putpmsg() pwrite() read() readv() recv() recvfrom() recvmsg() select() sem_timedwait() sem_wait() send() sendmsg() sendto() sigpause() [POSIX.1-2001 only (moves to "may" list in POSIX.1-2008)] sigsuspend() sigtimedwait() sigwait() sigwaitinfo() sleep() system() tcdrain() usleep() [POSIX.1-2001 のみ (POSIX.1-2008 で削除された)] wait() waitid() waitpid() write() writev()
The following functions may be cancelation points according to POSIX.1-2001 and/or POSIX.1-2008:
access()
asctime()
asctime_r()
catclose()
catgets()
catopen()
chmod() [POSIX.1-2008 で追加された]
chown() [POSIX.1-2008 で追加された]
closedir()
closelog()
ctermid()
ctime()
ctime_r()
dbm_close()
dbm_delete()
dbm_fetch()
dbm_nextkey()
dbm_open()
dbm_store()
dlclose()
dlopen()
dprintf() [POSIX.1-2008 で追加された]
endgrent()
endhostent()
endnetent()
endprotoent()
endpwent()
endservent()
endutxent()
faccessat() [POSIX.1-2008 で追加された]
fchmod() [POSIX.1-2008 で追加された]
fchmodat() [POSIX.1-2008 で追加された]
fchown() [POSIX.1-2008 で追加された]
fchownat() [POSIX.1-2008 で追加された]
fclose()
fcntl() (cmd 引数が何であっても)
fflush()
fgetc()
fgetpos()
fgets()
fgetwc()
fgetws()
fmtmsg()
fopen()
fpathconf()
fprintf()
fputc()
fputs()
fputwc()
fputws()
fread()
freopen()
fscanf()
fseek()
fseeko()
fsetpos()
fstat()
fstatat() [POSIX.1-2008 で追加された]
ftell()
ftello()
ftw()
futimens() [POSIX.1-2008 で追加された]
fwprintf()
fwrite()
fwscanf()
getaddrinfo()
getc()
getc_unlocked()
getchar()
getchar_unlocked()
getcwd()
getdate()
getdelim() [POSIX.1-2008 で追加された]
getgrent()
getgrgid()
getgrgid_r()
getgrnam()
getgrnam_r()
gethostbyaddr() [POSIX.1-2001 のみ (この関数は
POSIX.1-2008 で削除されている)]
gethostbyname() [POSIX.1-2001 のみ (この関数は
POSIX.1-2008 で削除されている)]
gethostent()
gethostid()
gethostname()
getline() [POSIX.1-2008 で追加された]
getlogin()
getlogin_r()
getnameinfo()
getnetbyaddr()
getnetbyname()
getnetent()
getopt() (opterr が 0 以外の場合)
getprotobyname()
getprotobynumber()
getprotoent()
getpwent()
getpwnam()
getpwnam_r()
getpwuid()
getpwuid_r()
gets()
getservbyname()
getservbyport()
getservent()
getutxent()
getutxid()
getutxline()
getwc()
getwchar()
getwd() [POSIX.1-2001 のみ (この関数は
POSIX.1-2008 で削除されている)]
glob()
iconv_close()
iconv_open()
ioctl()
link()
linkat() [POSIX.1-2008 で追加された]
lio_listio() [POSIX.1-2008 で追加された]
localtime()
localtime_r()
lockf() [POSIX.1-2008 で追加された]
lseek()
lstat()
mkdir() [POSIX.1-2008 で追加された]
mkdirat() [POSIX.1-2008 で追加された]
mkdtemp() [POSIX.1-2008 で追加された]
mkfifo() [POSIX.1-2008 で追加された]
mkfifoat() [POSIX.1-2008 で追加された]
mknod() [POSIX.1-2008 で追加された]
mknodat() [POSIX.1-2008 で追加された]
mkstemp()
mktime()
nftw()
opendir()
openlog()
pathconf()
pclose()
perror()
popen()
posix_fadvise()
posix_fallocate()
posix_madvise()
posix_openpt()
posix_spawn()
posix_spawnp()
posix_trace_clear()
posix_trace_close()
posix_trace_create()
posix_trace_create_withlog()
posix_trace_eventtypelist_getnext_id()
posix_trace_eventtypelist_rewind()
posix_trace_flush()
posix_trace_get_attr()
posix_trace_get_filter()
posix_trace_get_status()
posix_trace_getnext_event()
posix_trace_open()
posix_trace_rewind()
posix_trace_set_filter()
posix_trace_shutdown()
posix_trace_timedgetnext_event()
posix_typed_mem_open()
printf()
psiginfo() [POSIX.1-2008 で追加された]
psignal() [POSIX.1-2008 で追加された]
pthread_rwlock_rdlock()
pthread_rwlock_timedrdlock()
pthread_rwlock_timedwrlock()
pthread_rwlock_wrlock()
putc()
putc_unlocked()
putchar()
putchar_unlocked()
puts()
pututxline()
putwc()
putwchar()
readdir()
readdir_r()
readlink() [POSIX.1-2008 で追加された]
readlinkat() [POSIX.1-2008 で追加された]
remove()
rename()
renameat() [POSIX.1-2008 で追加された]
rewind()
rewinddir()
scandir() [POSIX.1-2008 で追加された]
scanf()
seekdir()
semop()
setgrent()
sethostent()
setnetent()
setprotoent()
setpwent()
setservent()
setutxent()
sigpause() [POSIX.1-2008 で追加された]
stat()
strerror()
strerror_r()
strftime()
symlink()
symlinkat() [POSIX.1-2008 で追加された]
sync()
syslog()
tmpfile()
tmpnam()
ttyname()
ttyname_r()
tzset()
ungetc()
ungetwc()
unlink()
unlinkat() [POSIX.1-2008 で追加された]
utime() [POSIX.1-2008 で追加された]
utimensat() [POSIX.1-2008 で追加された]
utimes() [POSIX.1-2008 で追加された]
vdprintf() [POSIX.1-2008 で追加された]
vfprintf()
vfwprintf()
vprintf()
vwprintf()
wcsftime()
wordexp()
wprintf()
wscanf()
An implementation may also mark other functions not specified in the standard as cancelation points. In particular, an implementation is likely to mark any nonstandard function that may block as a cancelation point. (This includes most functions that can touch files.)
It should be noted that even if an application is not using asynchronous cancelation, that calling a function from the above list from an asynchronous signal handler may cause the equivalent of asynchronous cancelation. The underlying user code may not expect asynchronous cancelation and the state of the user data may become inconsistent. Therefore signals should be used with caution when entering a region of deferred cancelation.
どちらの実装もいわゆる 1:1 実装、すなわち個々のスレッドが カーネルのスケジューリング実体にマッピングされる。 どちらのスレッドの実装も Linux の clone(2) システムコールを利用している。 NPTL では、スレッド同期の基本機構 (mutex や スレッドの join 等) は Linux の futex(2) システムコールを使って実装されている。
LinuxThreads の実装では POSIX.1 仕様から逸脱している点が いくつかある。以下に示すような点がある:
NPTL は内部でリアルタイムシグナルのうち最初の 2つの番号を使用しており、これらのシグナルはアプリケーションでは使用できない。詳細は
nptl(7) を参照のこと。
NPTL にも POSIX.1 に準拠していない点が少なくとも一つある:
NPTL の標準非準拠な点のうちいくつかは以前のカーネルでのみ発生する:
NPTL の実装では以下の点についても注意すること:
bash$ getconf GNU_LIBPTHREAD_VERSION NPTL 2.3.4
ぞれ以前の glibc のバージョンでは、以下のようなコマンドで デフォルトのスレッド実装を判定することができる。
bash$ $( ldd /bin/ls | grep libc.so | awk '{print $3}' ) | \
egrep -i 'threads|nptl'
Native POSIX Threads Library by Ulrich Drepper et al
bash$ $( LD_ASSUME_KERNEL=2.2.5 ldd /bin/ls | grep libc.so | \
awk '{print $3}' ) | egrep -i 'threads|nptl'
linuxthreads-0.10 by Xavier Leroy
pthreads の各種マニュアルページ、例えば: pthread_atfork(3), pthread_attr_init(3), pthread_cancel(3), pthread_cleanup_push(3), pthread_cond_signal(3), pthread_cond_wait(3), pthread_create(3), pthread_detach(3), pthread_equal(3), pthread_exit(3), pthread_key_create(3), pthread_kill(3), pthread_mutex_lock(3), pthread_mutex_unlock(3), pthread_mutexattr_destroy(3), pthread_mutexattr_init(3), pthread_once(3), pthread_spin_init(3), pthread_spin_lock(3), pthread_rwlockattr_setkind_np(3), pthread_setcancelstate(3), pthread_setcanceltype(3), pthread_setspecific(3), pthread_sigmask(3), pthread_sigqueue(3), and pthread_testcancel(3)