Professional Documents
Culture Documents
Unit - 3 - Threads
Unit - 3 - Threads
• DEFINATION OF THREADS
• TYPES OF THREAD PROCESS(SINGLE AND
MULTITHREADED PROCESS)
• BENEFITS OF MULTITHREAD
• MULTITHREADING MODELS(MANY- TO ONE
MODEL,ONE –TO –ONE MODEL,MANY TO MANY
MODEL)
DEFINITION OF THREADS
• Imagine you are using a web browser to access
website say facebook. The browser is the process
and within that process there are multiple
threads working together to provide you
browsing experience.
a. Main thread tab manager: Control and
coordinates the event between you and network
b. Graphics: This is responsible for rendering the
visual element of the facebook
c. Networking thread: This thread handles network
requests ..etc..
Definition of Thread
- Thread is light weight process created by process.
- A thread is a semi process that has its own stack, and executes a given
piece of code.
- Thread is a single sequence stream within a process.
- All these threads execute in parallel and The cpu switches rapidly back and
forth among the threads giving illusion that the threads are running in
parallel.
- Like a traditional process i.e process with one thread, a thread can be in
any several states(running, blocked, ready, terminated).
- Threads has its own:
- Program counter that keep track of which instruction to execute next
- System registers which holds its current working variables
- Stack which contains the execution history.
Example of thread
Definition of threads
What are the reasons for having these mini-processes, called
threads
- The main reason for having threads is that in many
applications, multiple activities are going on at once.
- By decomposing such an application into multiple sequential
threads that run in parallel.
Similarities between process and
thread
• Like processes threads share cpu and only one
thread is running at a time
• Like processes threads within a process
execute sequentially
• Like processes thread can create children
• Like a process a thread can be in any one of
several states like running, ready, etc.
• Like process threads have program counter,
stack, registers and state.
Dissimilarities between process and
thread.
• Unlike processes threads are not independent
of one another
• Threads within the same process share an
address space.
• Unlike processes threads can access every
address in the task
• Unlike process threads are design to assist one
another.
Advantages of threads
• Threads minimize the context switching time
• Use of threads provides concurrency within a
process
• Efficient communication
• It is more easy to create and context switch
threads
• Threads can execute in parallel on
multiprocessors.
• Threads have full access to address space(easy
sharing)
Types of Threads
• 1. kernel level thread
• 2. user level thread
Types of threads
User level thread Kernel level thread
If one user level thread perform If one kernel thread perform blocking
blocking operation then entire operation then another thread within
process will be blocked same process can continue execution