This document compares threads and processes, explains multithreading, and discusses the differences between multithreading and multitasking. Threads are segments of a process that share resources and have less overhead than entire processes. Multithreading allows multiple threads within a process to run concurrently, improving efficiency. It differs from multitasking, which runs entire processes concurrently by switching the CPU between them, by having threads within a process share resources instead of processes.
2. What is the differences between threads and
processing in operating system?
Thread Processing
Its means a segment of a process Its means any program is in execution
Thread takes less time to terminate It takes more time to terminate
It takes less time for creation It takes more time for creation
Thread is more efficient in terms of communication The process is less efficient in terms of communication.
A Thread is lightweight as each thread in a process shares code,
data, and resources
The process is called the heavyweight process
Thread switching does not require calling an operating system and
causes an interrupt to the kernel.
Process switching uses an interface in an operating system.
If a user-level thread is blocked, then all other user-level threads
are blocked.
If one process is blocked then it will not affect the execution of
other processes
Threads share data with each other. The process does not share data with each other
No system call is involved, it is created using APIs. A system call is involved in it
Thread has Parents’ PCB, its own Thread Control Block, and Stack
and common Address space.
The process has its own Process Control Block, Stack, and
Address Space.
3. Briefly explain Multi-threading?
◦ Multithreading is the ability of a program or an operating system to enable more than one user
at a time without requiring multiple copies of the program running on the computer
◦ Multithreading is a CPU feature that allows two or more instruction threads to execute
independently while sharing the same process resources. A thread is a self-contained sequence
of instructions that can execute in parallel with other threads that are part of the same root
process.
◦ Multithreading allows multiple concurrent tasks can be performed within a single process. When
data scientists are training machine learning algorithms, a multithreaded approach to
programming can improve speed when compared to traditional parallel
multiprocessing programs.
4. How does Multithreading Work
◦ In programming, a thread maintains a list of information relevant to its execution, including the priority
schedule, exception handlers, a set of CPU registers, and stack state in the address space of its hosting
process.
◦ Parallel multiprocessing means the system is actually handling more than one thread at a given time.
Concurrent processing means that only one thread will be handled at a time, but the system will create
efficiencies by moving quickly between two or more threads.
◦ In addition, much of the parallel or concurrent processing is made available according to the vagaries of the
operating system. So in effect, to the human user, either parallel or concurrent process, or processes that are
mixed, are all experienced as parallelism in real-time.
◦ Different types of multithreading apply to various versions of operating systems and related controls that
have evolved in computing: for example, in pre-emptive multithreading, the context switch is controlled by
the operating system. Then there’s cooperative multithreading, in which context switching is controlled by the
thread. This could lead to problems, such as deadlocks if a thread is blocked waiting for a resource to
become free.
5. Basis for comparison Multiprocessing Multithreading
Basic Multiprocessing add CPUs to increase
computing power.
It creates multiple threads of a single process
to increase the computing power.
Execution Multiple processes are executed concurrently. Multiple threads of a single process are
executed concurrently.
6. What is the differences between multi-
threading and multi-tasking in operating
system?
Multi-tasking Multi-threading
In multitasking, users are allowed to perform many tasks by CPU. Many threads are created from a process through which computer
power is increased.
Multitasking involves often CPU switching between the tasks CPU switching is often involved between the threads.
In multitasking, the processes share separate memory. While in multithreading, processes are allocated the same memory.
The multitasking component involves multiprocessing. While the multithreading component does not involve
multiprocessing.
In multitasking, the CPU is provided in order to execute many tasks
at a time.
While in multithreading also, a CPU is provided in order to execute
many threads from a process at a time.
In multitasking, processes don’t share the same resources, each
process is allocated separate resources.
While in multithreading, each process shares the same resources
Multitasking is slow compared to multithreading. While multithreading is faster.
In multitasking, termination of a process takes more time. While in multithreading, termination of thread takes less time.
Isolation and memory protection exist in multitasking. Isolation and memory protection does not exist in multithreading.
It helps in developing efficient programs It helps in developing efficient operating systems.