3.9. The Native POSIX Threads Library (NPTL)
The Linux threading library in all the released versions of Linux prior to kernel version 2.6 is known as LinuxThreads. This library has been supported by the GNU C library since glibc 2.0, although using the POSIX APIs is not really POSIX-compliant. Starting in the 2.6 kernel, NPTL was introduced. It provides a significant performance improvement over LinuxThreads. NPTL is also far more compliant with the POSIX specification than the LinuxThreads package was. However, simply using the 2.6 kernel does not mean that the NPTL is being used. All modern Linux distributions ship NPTL as the default, even if they ship both NPTL and LinuxThreads.
Issue the following command to see which POSIX implementation you are using:
$ getconf GNU_LIBPTHREAD_VERSION NPTL 0.61 This was returned from SuSE 9.1 installation $ getconf GNU_LIBPTHREAD_VERSION NPTL 2.3.3 This was returned from Fedora 2.6.9-1.667 Installation. $ getconf GNU_LIBPTHREAD_VERSION linuxthreads-0.10 This was returned from an old RedHat installation
To tell which compiler suite the Linux distribution was compiled and linked with, use the following method.
To find the libpthreads library linked with /bin/ls:
$ ldd /bin/ls | grep libc.so.6 libc.so.6 => /lib/tls/i586/libc.so.6 (0x00b9c000) $ /lib/tls/i586/libc.so.6 GNU C Library stable release version 2.3.3, by Roland McGrath et al. Copyright (C) 2004 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Compiled by GNU CC version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3). Compiled on a Linux 2.4.20 system on 2004-10-27. Available extensions: GNU libio by Per Bothner crypt add-on version 2.1 by Michael Glad and others Native POSIX Threads Library by Ulrich Drepper et al The C stubs add-on version 2.1.2. BIND-8.2.3-T5B NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk Glibc-2.0 compatibility add-on by Cristian Gafton GNU Libidn by Simon Josefsson Thread-local storage support included. For bug reporting instructions, please see: <http://www.gnu.org/software/libc/bugs.html>.
As the preceding output shows, the libc.so.6 is linked with the Native POSIX Threads Library by Ulrich Drepper.
NPTL implements the one-on-one threading model; that is, there is a one-to-one relationship between a user thread and a kernel thread. NPTL also implements the interprocess POSIX synchronization primitives. Specifically, the thread option PTHREAD_PROCESS_SHARED is now supported.
3.9.1. Maximum Number of Threads
The maximum number of threads an application can create on a Linux system varies in different Linux distributions. Running SUSE version 9.1 on a two-processor system with 2GB of memory yielded 16,317 pthreads created before pthread_create returned an EAGAIN error number. An EGAIN may mean that the application ran into some system-imposed limit. The application was programmed to create threads with a stack size of 16,384, which is the minimum stack size allowed for creating threads. Before setting the stack size to 16,384, the application would fail pthread creation at 1,021 with a return code of ENOMEM. In any case, 8,000 and even 16,000 threads is enough to satisfy any application program needs for creating threads.
To create a large number of threads in Linux, be sure to do the following:
Chapters 4, 5, and 6 contain more details on POSIX threads supported and their differences compared to NPTL.