Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
6 views

Thread

Uploaded by

recu12121
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Thread

Uploaded by

recu12121
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Thread:

Thread is a separate execution path. It is a lightweight process that the


operating system can schedule and run concurrently with other
threads. The operating system creates and manages threads, and they
share the same memory and resources as the program that created
them. This enables multiple threads to collaborate and work efficiently
within a single program.
A thread is a single sequence stream within a process. Threads are
also called lightweight processes as they possess some of the
properties of processes. Each thread belongs to exactly one process.
In an operating system that supports multithreading, the process can
consist of many threads. But threads can be effective only if CPU is
more than 1 otherwise two threads have to context switch for that
single CPU.

Types of threads:
Threads are of two types. These are described below.
 User Level Thread
 Kernel Level Thread

User Level Threads


User Level Thread is a type of thread that is not created using system
calls. The kernel has no work in the management of user-level threads.
User-level threads can be easily implemented by the user. In case
when user-level threads are single-handed processes, kernel-level
thread manages them. Let’s look at the advantages and disadvantages
of User-Level Thread.
Advantages of User-Level Threads
 Implementation of the User-Level Thread is easier than Kernel
Level Thread.
 Context Switch Time is less in User Level Thread.
 User-Level Thread is more efficient than Kernel-Level Thread.
 Because of the presence of only Program Counter, Register Set,
and Stack Space, it has a simple representation.

Disadvantages of User-Level Threads

 There is a lack of coordination between Thread and Kernel.


 Inc case of a page fault, the whole process can be blocked.

Kernel Level Threads

A kernel Level Thread is a type of thread that can recognize the


Operating system easily. Kernel Level Threads has its own thread
table where it keeps track of the system. The operating System Kernel
helps in managing threads. Kernel Threads have somehow longer
context switching time. Kernel helps in the management of threads.
Advantages of Kernel-Level Threads
 It has up-to-date information on all threads.
 Applications that block frequency are to be handled by the Kernel-
Level Threads.
 Whenever any process requires more time to process, Kernel-Level
Thread provides more time to it.

Disadvantages of Kernel-Level threads


 Kernel-Level Thread is slower than User-Level Thread.
 Implementation of this type of thread is a little more complex than a
user-level thread.
Multithreading Models:
Some operating system provide a combined user level thread and Kernel
level thread facility. Solaris is a good example of this combined
approach. In a combined system, multiple threads within the same
application can run in parallel on multiple processors and a blocking
system call need not block the entire process. Multithreading models are
three types
 Many to many relationship.
 Many to one relationship.
 One to one relationship.

Many to Many Model


The many-to-many model multiplexes any number of user threads onto
an equal or smaller number of kernel threads.
The following diagram shows the many-to-many threading model where
6 user level threads are multiplexing with 6 kernel level threads. In this
model, developers can create as many user threads as necessary and the
corresponding Kernel threads can run in parallel on a multiprocessor
machine. This model provides the best accuracy on concurrency and
when a thread performs a blocking system call, the kernel can schedule
another thread for execution.
Many to One Model
Many-to-one model maps many user level threads to one Kernel-level
thread. Thread management is done in user space by the thread library.
When thread makes a blocking system call, the entire process will be
blocked. Only one thread can access the Kernel at a time, so multiple
threads are unable to run in parallel on multiprocessors.
If the user-level thread libraries are implemented in the operating system
in such a way that the system does not support them, then the Kernel
threads use the many-to-one relationship modes.
One to One Model
There is one-to-one relationship of user-level thread to the kernel-level
thread. This model provides more concurrency than the many-to-one
model. It also allows another thread to run when a thread makes a
blocking system call. It supports multiple threads to execute in parallel
on microprocessors.
Disadvantage of this model is that creating user thread requires the
corresponding Kernel thread. OS/2, windows NT and windows 2000 use
one to one relationship model.
Difference between User-Level & Kernel-Level
Thread:
S.N. User-Level Threads Kernel-Level Thread

1 User-level threads are faster to create Kernel-level threads are slower


and manage. to create and manage.

2 Implementation is by a thread library at Operating system supports


the user level. creation of Kernel threads.
3 User-level thread is generic and can Kernel-level thread is specific to
run on any operating system. the operating system.

4 Multi-threaded applications cannot take Kernel routines themselves can


advantage of multiprocessing. be multithreaded.

You might also like