GP OS Threads
GP OS Threads
Threads
Thread is an execution unit that consists of its own program counter, a stack, and a set
of registers. Threads are also known as Lightweight processes. Threads are a popular
way to improve the application through parallelism. The CPU switches rapidly back and
forth among the threads giving the illusion that the threads are running in parallel. As
each thread has its own independent resource for process execution, multiple
processes can be executed parallelly by increasing the number of threads.
Types of Thread
● User threads are above the kernel and without kernel support. These are the
threads that application programmers use in their programs.
● Kernel threads are supported within the kernel of the OS itself. All modern OSs
support kernel-level threads, allowing the kernel to perform multiple
simultaneous tasks and/or to service multiple kernel system calls simultaneously.
One Program contains One Process can contain One thread can belong to
many processes. several threads. exactly one process.
1
Multithreading
Multithreading is a phenomenon of executing multiple threads at the same time. For
example, in a browser, multiple tabs can be different threads. MS Word uses multiple
threads: one thread to format the text, another thread to process inputs, etc.
Multithreading Models
The user threads must be mapped to kernel threads, by one of the following strategies:
2
One to One Model
The one-to-one model creates a separate kernel thread to handle each and every user
thread. Most implementations of this model place a limit on how many threads can be
created. Linux and Windows from 95 to XP implement the one-to-one model for
threads.
3
Many to Many Model
The many to many model multiplexes any number of user threads onto an equal or
smaller number of kernel threads, combining the best features of the one-to-one and
many-to-one models. Blocking the kernel system calls does not block the entire process.