AOS 5 Threads
AOS 5 Threads
Threads
Processes
The Process Model
Process Creation
Process Termination
Thread
Motivation
Most modern applications are multithreaded
Threads run within application
Multiple tasks with the application can be implemented by
separate threads
Process creation is heavy-weight while thread creation is light-
weight
Can simplify code, increase efficiency
Kernels are generally multithreaded
Multithreading Models
Many-to-One
One-to-One
Many-to-Many
Many-to-One
One-to-One
• Each user-level thread maps to kernel thread
• Creating a user-level thread creates a kernel thread
• Number of threads per process sometimes restricted due to
overhead
• Examples
• Windows
• Linux
• Solaris 9 and later
Many-to-Many Model
• Allows many user level threads to be
mapped to many kernel threads
• Allows the operating system to create a
sufficient number of kernel threads
• Examples
– Solaris prior to version 9
– Windows with the Thread Fiber
package
Two-level Model
• Similar, to M:M, except that it allows a
user thread to be bound to kernel
thread
• Examples
– Tru64 UNIX
– Solaris 8 and earlier
TYPES OF THREADS
There are two types of threads
User-Level Threads
• All thread management is done by the application
• The kernel is not aware of the existence of threads
Kernel-Level Threads
• W2K, Linux, and OS/2 are examples of this approach
• Kernel maintains context information for the process and
the threads
• Scheduling is done on a thread basis
Thread Libraries
Benefits of Threads
Responsiveness – may allow continued execution if part
of process is blocked, especially important for user
interfaces
Resource Sharing – threads share resources of
process, easier than shared memory or message
passing
Economy – cheaper than process creation, thread
switching lower overhead than context switching
Scalability – process can take advantage of
multiprocessor architectures