0% found this document useful (0 votes)
26 views

Thread

Threads provide benefits like responsiveness, resource sharing, and economy over process creation. They allow continued execution if part of a process is blocked. Threads share resources within a process like memory, making communication easier than other techniques. Thread switching has lower overhead than process context switching. A process is an instance of a running program, while a thread is a segment that can run independently and concurrently within a process. Threads are lighter weight than processes and can share resources. If a thread blocks, other threads in the process may continue running whereas blocked processes block the entire program. Context switching is faster between threads than processes. There are different models for mapping user and kernel threads. In many-to-one mapping,
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)
26 views

Thread

Threads provide benefits like responsiveness, resource sharing, and economy over process creation. They allow continued execution if part of a process is blocked. Threads share resources within a process like memory, making communication easier than other techniques. Thread switching has lower overhead than process context switching. A process is an instance of a running program, while a thread is a segment that can run independently and concurrently within a process. Threads are lighter weight than processes and can share resources. If a thread blocks, other threads in the process may continue running whereas blocked processes block the entire program. Context switching is faster between threads than processes. There are different models for mapping user and kernel threads. In many-to-one mapping,
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
You are on page 1/ 11

Threads

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:

 Parallelism on a multi-core system:


Single and Multithreaded Processes
User Threads and Kernel Threads

• User threads - management done by user-level threads library


• Three primary thread libraries:
– POSIX Pthreads
– Windows threads
– Java threads
• Kernel threads - Supported by the Kernel
• Examples – virtually all general purpose operating systems,
including:
– Windows
– Solaris
– Linux
– Tru64 UNIX
– Mac OS X
Multithreading Models

• 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

User threads are implemented by Kernel threads are implemented by Operating


1. Implemented by
users. System (OS).

The operating System doesn’t Kernel threads are recognized by Operating


2. Recognize
recognize user- level threads. System.

Implementation of User threads is Implementation of Kernel- Level thread is


3. Implementation
easy. complicated.

4. Context switch time Context sw itch time is less. Context sw itch time is more.

Context sw itch requires no hardw are


5. Hardware support Hardw are support is needed.
support.

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.

Multithread applications cannot take


7. Multithreading Kernels can be multithreaded.
advantage of multiprocessing.

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.

You might also like