Chapter 04 - Threads
Chapter 04 - Threads
Threads
◼ Types of Threads
◼ Multithreading Models
◼ Threading Issues
◼ A thread shares with other threads belonging to the same process its code
section, data section, and other OS resources such as an open file etc.
[Fig. 4.1]
◼ Responsiveness
◼ Resource Sharing
◼ Economy
◼ Scalability
1. User Threads:
➢ Kernel threads are directly supported by the OS. The kernel performs
thread creation, scheduling and management in kernel space.
◼ Examples:
➢ Solaris Green Threads
➢ GNU Portable Threads
◼ Drawbacks:
➢ The entire process will block
if a single user thread makes
a block system call.
➢ Since only one thread can access
the kernel at a time, multiple threads
are unable to run in parallel
on multiprocessors.
◼ Examples:
➢ Windows NT/XP/2000
➢ Linux
➢ Solaris 9 and later
◼ Drawbacks:
➢ Creating a user thread requires creating the corresponding kernel
thread, which is a overhead. Because of this reason most
implementations of this model restrict the number of threads supported
by the system.
[Fig. 4.4:
One-to-One Multithreading Model]
◼ Examples:
➢ Solaris prior to version 9
➢ Windows NT/2000 with the Thread Fiber package
[Fig. 4.5:
Many-to-Many Multithreading Model]
◼ Thread cancellation
◼ Signal handling
◼ Thread pools
◼ Thread-specific data
◼ Does fork ( ) duplicate the whole process (i.e. all threads within the process) or
only the calling thread?
◼ To avoid this situation some UNIX systems has chosen 2 versions of fork ( ) :
◼ exec ( ) system call has the same meaning: If a thread invokes the exec ( )
system call, the program specified in the parameter of exec ( ) will replace the
entire process including all the threads.
◼ Signals are used in UNIX systems to notify a process that a particular event has
occurred.
◼ Threads that belongs to a process usually share the data of that process.
◼ However, each thread might need its own copy of certain data in some
circumstances. These are called thread specific data.
◼ Useful when you do not have control over the thread creation process (i.e.,
when using a thread pool)