Home > CS4310: Operating Systems > Process Management: ThreadsProcess Management: Threads
Thread: Basic unit of CPU utilization.
Purpose: Threads let us avoid incurring the overhead of creating and managing separate PCBs.
Structure:
Example: A word processor may have a thread for getting keystrokes from the user, another for spellcheck, and another for graphics.
TODO Diagram of single and multithreaded process.
Today: Jernels and moden applications are generall multithreaded.
Multicore systems put pressure on programmars.
Challenges include:
Parallelism: System can do more than one task simultaneously.
Concurrency: Supports more than one task making progress.
Data Parallelism: Split data across multiple cores, same operation on each. You want to sum an array on a dual-core system. You could have one core sum-up the first half, and the other core do the latter half.Example: Data Parallelism
Task Parallelism: Distribute threads across cores. Each thread can do unique operations on same or different data.
Identifies performance gains from adding additional cores to an application that has serial and parallel components.
\text{speedup} \le \frac{1}{ S + \frac{1-S}{N} } \\~\\ \small \textit{where $S$ is serial portion; $N$ is processing cores}
The serial portion has a disproportionate effect on performance.
User: Supported above the kernel, managed without kernel support
Kernel: Managed directly by the Kernel
All modern operating systems support multithreading.
Few systems currently use this model, as one thread blocks the rest.
Examples: Solaris Green Threads Library
More concurrency. Number of threads per process sometimes restricted due to overhead.
Examples: Windows, Linux
Multiplexes many user-level threads to smaller or equal number of kernel threads.
Examples: Windows with ThreadFiber package
Like many-to-many except a user thread can also be bound to a kernel thread.
Examples: Tru64 UNIX
Provides programmer with API for creating and managing threads
Two Primary Implementation:
Examples:
- Windows: kernel-level
- Java: typically kernel-level
- Pthread: any
Managed by the JVM
You can create a thread by implementing the Runnable
interface.
class Mytask extends SomeOtherClass implements Runnable {
// ...
}
Note: Don’t extend the Thread class, you’ll lock-out extending anything else!