• Thread library provides programmer with API for creating and managing threads
• Two primary ways of implementing
- Library entirely in user space
- Kernel-level library supported by the OS
Thread Library
Labels: OS 5
Multithreading Methods
Multithreading Methods
• Many-to-One
• One-to-One
• Many-to-Many
MANY-TO-ONE
• Many user-level threads mapped to single kernel thread
• Examples:
- Solaris Green Threads
- GNU Portable Threads
----------
ONE-TO-ONE
• Each user-level thread maps to kernel thread
• Examples
- Windows NT/XP/2000
- Linux
- Solaris 9 and later
----------
MANY-TO-MANY
• 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
Labels: OS 5
Kernel Thread
• Supported by the Kernel
• OS manages threads
- Slower to create and manage because of system calls
- A blocking system call will not cause the entire process to block.
- The kernel can schedule threads on different CPUs.
Labels: OS 5
User Thread
• Thread management done by user-level threads library
• A blocking system call will cause the entire process to block
- OS is unaware of threads
• The kernel cannot schedule threads on different CPUs.
• Example: Pthread, a POSIX standard (IEEE 1003.1c) API for thread creation and synchronization.
Labels: OS 5
Benefits of Multi-Threaded Programming
• Responsiveness
- User interaction in parallel with data retrieval
• Utilization of MP Architectures
• Resource Sharing between Threads (vs. Process)
E.g. Synchronization by accessing shared data
• Economy (vs. Process)
- If the task is the same, why not share the code?
- In Solaris 2, creating a process is about 30 times slower than threads. Context switch threads is about 5 times slower.
Labels: OS 5
Thread
• A piece of code that run in concurrent with other threads.
• Each thread is a statically ordered sequence of instructions.
• Threads are being extensively used express concurrency on both single and multiprocessors machines.
• Programming a task having multiple threads of control – Multithreading or Multithreaded Programming.
•

Labels: OS 5