Ch03-Multithread Programming
Ch03-Multithread Programming
Multithreaded Programming
Introduction
• Thread is a sequential flow of tasks within a
process.
• Threads are used to increase the performance of
the applications.
• Each thread has its own program counter, stack, and
set of registers.
• Threads are also termed lightweight processes as
they share common resources.
• Eg: While playing a movie on a device the audio and
video are controlled by different threads in the
background.
• The below diagram shows the difference between a single-
threaded process and a multithreaded process and the
resources that are shared among threads in a multithreaded
process.
• Components of Thread
A thread has the following three components:
1.Program Counter: Tracks the current instruction
being executed by the thread.
2.Register Set:- Hold temporary data and
intermediate results for the thread’s execution.
3.Stack space:- Tracks the current instruction being
executed by the thread.
• Why do We Need Threads?
executed by the thread.