Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads (7 th Edition)
4.2 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Single and Multithreaded Processes
4.3 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Benefits Responsiveness Resource Sharing Economy Utilization of multiprocessor architectures
4.4 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition User Threads Thread management done by user-level threads library Three primary thread libraries: POSIX Pthreads Win32 threads Java threads
4.5 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Kernel Threads Supported by the Kernel Examples Windows XP/2000 Solaris Linux Tru64 UNIX Mac OS X There must exists a relationship between user thread and kernel thread.
4.6 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Multithreading Models Many-to-One One-to-One Many-to-Many
4.7 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Many-to-One Many user-level threads mapped to single kernel thread Examples: Solaris Green Threads GNU Portable Threads
4.8 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Many-to-One Model
4.9 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition One-to-One Each user-level thread maps to kernel thread Examples Windows NT/XP/2000 Linux Solaris 9 and later
4.10 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition One-to-one Model
4.11 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition 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 Solaris prior to version 9 Windows NT/2000 with the ThreadFiber package
4.12 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Many-to-Many Model
4.13 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Threading Issues Thread cancellation of target thread (page 139) Asynchronous Cancellation Deferred Cancellation Signal handling (page 139) Synchronous and asynchronous received signal.
4.14 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Threading Issues (Cont.) Thread pools (page 141) Thread-specific data (page 142) Create Facility needed for data private to thread
4.15 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Thread Cancellation Terminating a thread before it has finished Two general approaches: Asynchronous cancellation terminates the target thread immediately Deferred cancellation allows the target thread to periodically check if it should be cancelled
4.16 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Signal handling Synchronous and asynchronous received signal. Every Signal may be handled by one of two possible handlers: A default signal handler A user-defined signal handler
4.17 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Thread Pools Create a number of threads in a pool where they await for work Advantages: Usually slightly faster to service a request with an existing thread than create a new thread Allows the number of threads in the application(s) to be bound to the size of the pool
4.18 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Thread Specific Data Allows each thread to have its own copy of data Useful when you do not have control over the thread creation process (i.e., when using a thread pool)
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition End of Chapter 4 NAT