|
|
HP-UX Process Management: White Paper > Chapter 1 Process ManagementThread Models |
|
Industrywide, threads are implemented according to four distinct models:
User-space threads (M x 1, based on POSIX draft 4 threads) are created, terminated, synchronized, scheduled, and so forth using interfaces provided by a threads library. Creation, termination, and synchronization operations can be performed extremely fast using user-space threads. Because user-space threads are not directly visible to the kernel (which is aware only of the overriding process containing the user-space threads), user-space threads (M x 1) require no kernel support. As shown in the following figure, all thread management is done in user space, so there is no overhead associated with crossing the kernel boundary. If one thread blocks, the entire process blocks. When this happens, the benefit of threads parallelism is lost. Wrappers around various system calls can reduce some of the blocking, but at a cost to performance. User-space threads have been on HP-UX since release 9.0 with DCE and on all 10.0 systems. With kernel threads (1 thread to one process, or 1 x 1), each user thread has a corresponding kernel thread. Thus, there is full kernel support for threads. Each thread is independently schedulable by the kernel, so if one thread blocks, others can still run. Creation, termination, and synchronization can be slower with kernel threads than user threads, since the kernel must be involved in all thread management. Overhead may be greater, but more concurrency is possible using kernel threads, even with a uniprocessor system. As a result, total application performance with kernel-space threads surpasses that of user-space threads. Note, however, that developers must be more careful when creating large amounts of threads, as each thread adds more weight to the process and more overhead to the system The model of maximal flexibility in the number of threads to processes (M x N) provides the developer with both user-space and kernel-space threads. The M x N model allows threads to be bound or unbound from kernel threads. Users can use unbound user space threads to take advantage of thread management occurring in user space. Bound threads enable use of the independent kernel scheduling provided for by kernel threads, as well as the true parallelism capabilities (both logical and physical) of an MP machine. The combination of user-space and kernel-space threads allow for extremely fast and efficient thread creation, termination, synchronization, and context switching, and thus, better performance and more system throughput than either 1 x 1 or M x 1 model. Developers need not worry about additional threads adding weight to the process or overhead to the system, as in the user-space threads (1 x 1) model. Further, blocking does not require the kernel to context switch to another process; another thread in the process will execute next. Because the M x N model is the most powerful and flexible for programmers, it is also the most complex. Debugging can be difficult. HP-UX release 10.30 implements the 1 x 1 (kernel-space threads) version of IEEE Portable Operating System Interface standard threads, (POSIX 1003.1c, based on final draft 10). Pthreads includes functions and application programming interfaces (APIs) to support multiple flows of control (threads) within a process. Using pthreads enables developers to create source-code portable applications. For details on pthread functions, attributes, stack information, and so forth, consult the pthread.h file.
|
|