0% found this document useful (0 votes)
15 views1 page

Understanding Threads and Multithreading

A thread is a lightweight process that allows for parallel execution within a process, enabling tasks like browser tabs or MS Word functions to run concurrently. Threads share memory space and resources, leading to advantages such as improved responsiveness, faster context switching, and better utilization of multiprocessor systems. However, each thread maintains its own stack and registers, differentiating it from processes that operate in separate memory spaces.

Uploaded by

anvidsahu689
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views1 page

Understanding Threads and Multithreading

A thread is a lightweight process that allows for parallel execution within a process, enabling tasks like browser tabs or MS Word functions to run concurrently. Threads share memory space and resources, leading to advantages such as improved responsiveness, faster context switching, and better utilization of multiprocessor systems. However, each thread maintains its own stack and registers, differentiating it from processes that operate in separate memory spaces.

Uploaded by

anvidsahu689
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

What is a Thread?

A thread is a path of execution within a process. A process can contain


multiple threads.
Why Multithreading?
A thread is also known as lightweight process. The idea is to achieve
parallelism by dividing a process into multiple threads. 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. More advantages of multithreading are discussed below
Process vs Thread?
The primary difference is that threads within the same process run in a
shared memory space, while processes run in separate memory spaces.
Threads are not independent of one another like processes are, and as a
result threads share with other threads their code section, data section,
and OS resources (like open files and signals). But, like process, a
thread has its own program counter (PC), register set, and stack space.
Advantages of Thread over Process
1. Responsiveness: If the process is divided into multiple threads, if one
thread completes its execution, then its output can be immediately
returned.
2. Faster context switch: Context switch time between threads is lower
compared to process context switch. Process context switching requires
more overhead from the CPU.
3. Effective utilization of multiprocessor system: If we have multiple
threads in a single process, then we can schedule multiple threads on
multiple processor. This will make process execution faster.
4. Resource sharing: Resources like code, data, and files can be shared
among all threads within a process.
Note: stack and registers can’t be shared among the threads. Each thread
has its own stack and registers.

You might also like