Chapter 2 Extra
Chapter 2 Extra
Context Switching
Example : Suppose that multiple processes are stored in a Process Control Block
(PCB). One process is running state to execute its task with the use of CPUs. As
the process is running, another process arrives in the ready queue, which has a high
priority of completing its task using CPU. Here we used context switching that
switches the current process with the new process requiring the CPU to finish its
tasks. While switching the process, a context switch saves the status of the old
process in registers. When the process reloads into the CPU, it starts the execution
of the process when the new process stops the old process. If we do not save the
state of the process, we have to start its execution at the initial level. In this way,
context switching helps the operating system to switch between the processes,
store or reload the process when it requires executing its tasks.
Threads
The process can be split down into so many threads. For example, in a browser,
many tabs can be viewed as threads. MS Word uses many threads - formatting text
from one thread, processing input from another thread, etc.
o Concept of multithreads
The main drawback of single threading systems is that only one task can
be performed at a time, so to overcome the drawback of this single
threading, there is multithreading that allows multiple tasks to be
performed.
o Benefits of threads
o Types of threads
User-level thread
The operating system does not recognize the user-level thread. User
threads can be easily implemented and it is implemented by the user. If a
user performs a user-level thread blocking operation, the whole process is
blocked. The kernel level thread does not know nothing about the user level
thread. The kernel-level thread manages user-level threads as if they are
single-threaded processes. examples: Java thread, etc.
1. The user threads can be easily implemented than the kernel thread.
2. User-level threads can be applied to such types of operating systems that
do not support threads at the kernel-level.
3. It is faster and efficient.
4. Context switch time is shorter than the kernel-level threads.
5. It does not require modifications of the operating system.
6. User-level threads representation is very simple. The register, PC, stack,
and mini thread control blocks are stored in the address space of the user-
level process.
7. It is simple to create, switch, and synchronize threads without the
intervention of the process.
1. User-level threads lack coordination between the thread and the kernel.
2. If a thread causes a page fault, the entire process is blocked.