Thread
Thread
Benefits
• Responsiveness – may allow continued
execution if part of process is blocked,
especially important for user interfaces
• Resource Sharing – threads share resources of
process, easier than shared memory or
message passing
• Economy – cheaper than process creation,
thread switching lower overhead than context
switching
• Scalability – process can take advantage of
multiprocessor architectures
Difference Table Between Process and Thread
Process Thread
A process is an instance of a program that is being executed or Thread is a segment of a process or a lightweight process that
processed. is managed by the scheduler independently.
Processes are independent of each other and hence don't Threads are interdependent and share memory.
share a memory or other resources.
Each process is treated as a new process by the operating The operating system takes all the user-level threads as a
system. single process.
If one process gets blocked by the operating system, then the If any user-level thread gets blocked, all of its peer threads also
other process can continue the execution. get blocked because OS takes all of them as a single process.
Context switching between two processes takes much time as Context switching between the threads is fast because they are
they are heavy compared to thread. very lightweight.
The data segment and code segment of each process are Threads share data segment and code segment with their peer
independent of the other. threads; hence are the same for other threads also.
The operating system takes more time to terminate a process. Threads can be terminated in very little time.
New process creation is more time taking as each new process A thread needs less time for creation.
takes all the resources.
Concurrency vs. Parallelism
Concurrent execution on single-core system:
• Many-to-One
• One-to-One
• Many-to-Many
Many-to-One
• Many user-level threads
mapped to single kernel thread
• One thread blocking causes all
to block
• Multiple threads may not run in
parallel on muticore system
because only one may be in
kernel at a time
• Few systems currently use this
model
• Examples:
– Solaris Green Threads
– GNU Portable Threads
One-to-One
• Each user-level thread maps to kernel
thread
• Creating a user-level thread creates a
kernel thread
• More concurrency than many-to-one
• Number of threads per process
sometimes restricted due to
overhead
• Examples
– Windows
– Linux
– Solaris 9 and later
Many-to-Many Model
• Allows many user level
threads to be mapped to
many kernel threads
• Allows the operating
system to create a
sufficient number of
kernel threads
• Solaris prior to version 9
• Windows with the
ThreadFiber package
. No. Parameters User Level Thread Kernel Level Thread
4. Context switch time Context sw itch time is less. Context sw itch time is more.
If one user- level thread performs a If one kernel thread performs a blocking
6. Blocking operation blocking operation then the entire operation then another thread can continue
process w ill be blocked. execution.
Creation and User- level threads can be created Kernel- level level threads take more time to
8.
Management and managed more quickly. create and manage.
Any operating system can support Kernel- level threads are operating system-
9. Operating System
user- level threads. specific.
The thread library contains the code The application code does not contain thread
for thread creation, message management code. It is merely an API to the
10. Thread Management
passing, thread scheduling, data kernel mode. The W indow s operating system
transfer, and thread destroying makes use of this feature.