Download Multithreading and Thread Libraries: An In-depth Look and more Slides Operating Systems in PDF only on Docsity!
Lecture 7
Chapter 4: Threads (cont)
Chapter 4: Threads
- Overview
- Multithreading Models
- Thread Libraries
- Threading Issues
- Operating System Examples
- Windows XP Threads
- Linux Threads
ex: Solaris, Mach, Windows
ex: MS-DOS ex: Java VM ex: early UNIX
uniprogramming
multiprogramming
Process-Thread relationship
Single and Multithreaded Processes
Benefits
- Responsiveness : Continue even if part of an application is blocked due to I/O - Allow user interaction in one thread while image is loading in another.
- Resource Sharing : Memory / resource sharing is by default with threads. - Several different threads of activity within the same address space.
- Economy : It is more economical to create andDocsity.com
Multicore Scalability
Parallel Execution on a Multicore System
Concurrent Execution on a Single-core System
User Threads
- Thread management done by user-level threads library
- Three primary thread libraries:
- POSIX Pthreads
- Win32 threads
- Java threads
Kernel Threads
- Supported by the Kernel
- Examples
- Windows XP/
- Solaris
- Linux
- Tru64 UNIX
- Mac OS X
Many-to-One
- Many user-level threads mapped to single kernel thread.
- Thread management is done by the thread library in user space, - Is efficient, - But, entire process will block is a thread makes a blocking system call.
- Only one thread can access the kernel at a time, Docsity.com
One-to-One
- Each user-level thread maps to kernel thread.
- Provides more concurrency.
- No blocking due to another thread.
- Threads may run in parallel on multiprocessors.
- Creating a user thread requires creating the corresponding kernel thread. - Hence, OSes limit the number of threads.
Two-level Model
- Similar to many-to-many, except that it allows a user thread to be bound to kernel thread.
- Examples
- IRIX
- HP-UX
- Tru64 UNIX
- Solaris 8 and earlier
Pthreads
- May be provided either as user-level or kernel-level
- A POSIX standard (IEEE 1003.1c) API for thread creation and synchronization
- API specifies behavior of the thread library, implementation is up to development of the library
Java Threads
- Java threads are managed by the JVM
- Typically implemented using the threads model provided by underlying OS
- Java threads may be created by:
- Extending Thread class
- Implementing the Runnable interface
- Must define run() method
- Call start() method to initialize a thread
- Use join() method to wait for a thread Docsity.com