Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
36 views7 pages

O.S - Theory Assignment 02

1. A thread refers to a single sequential flow of execution within a process. A process can contain multiple threads that execute concurrently. 2. There are two types of threads: kernel-level threads that are managed by the operating system, and user-level threads that are managed by user-space libraries instead of the kernel. 3. There are three multithreading models: many-to-many, many-to-one, and one-to-one, which describe how user threads map to kernel threads.

Uploaded by

Haadi Khan
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)
36 views7 pages

O.S - Theory Assignment 02

1. A thread refers to a single sequential flow of execution within a process. A process can contain multiple threads that execute concurrently. 2. There are two types of threads: kernel-level threads that are managed by the operating system, and user-level threads that are managed by user-space libraries instead of the kernel. 3. There are three multithreading models: many-to-many, many-to-one, and one-to-one, which describe how user threads map to kernel threads.

Uploaded by

Haadi Khan
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/ 7

Operating System

Theory Assignment #02

Name : Muhammad Rohaan khan


Roll No : BSSE / SP-22 / 037
Section : B
Teacher : Mam Kiran Amjad
Q:1) What is Thread?

Ans). A thread refers to a single sequential flow of activities being executed in a process; it is also known as the thread of execution or
the thread of control. Now, thread execution is possible within any OS’s process. Apart from that, a process can have several threads. A
distinct programme counter, a stack of activation records as well as control blocks are used by each thread of the same process. Thread
is frequently described as a light technique.

Q:2) Explain the Thread Types?


Ans). In the operating system, there are two types of threads.

1. Kernel level thread.


2. User-level thread.

1. Kernel Level Thread:-

The kernel thread recognizes the operating system. There is a thread control block and process control block in the system for each
thread and process in the kernel-level thread. The kernel-level thread is implemented by the operating system. The kernel knows about
all the threads and manages them. The kernel-level thread offers a system call to create and manage the threads from user-space. The
implementation of kernel threads is more difficult than the user thread. Context switch time is longer in the kernel thread. If a kernel
thread performs a blocking operation, the Banky thread execution can continue. Example: Window Solaris.
Advantages of Kernel-level threads

1. The kernel-level thread is fully aware of all threads.


2. The scheduler may decide to spend more CPU time in the process of threads being large numerical.
3. The kernel-level thread is good for those applications that block the frequency.

Disadvantages of Kernel-level threads

1. The kernel thread manages and schedules all threads.


2. The implementation of kernel threads is difficult than the user thread.
3. The kernel-level thread is slower than user-level threads.

2. User-Level Thread:-

The operating system does not recognize the user-level thread. User threads can be easily implemented and it is
implemented by the user. If a user performs a user-level thread blocking operation, the whole process is blocked. The kernel
level thread does not know nothing about the user level thread. The kernel-level thread manages user-level threads as if they
are single-threaded processes?examples: Java thread, POSIX threads, etc.
Advantages of User-level threads

1. The user threads can be easily implemented than the kernel thread.
2. User-level threads can be applied to such types of operating systems that do not support threads at the kernel-level.
3. It is faster and efficient.
4. Context switch time is shorter than the kernel-level threads.
5. It does not require modifications of the operating system.
6. User-level threads representation is very simple. The register, PC, stack, and mini thread control blocks are stored in
the address space of the user-level process.
7. It is simple to create, switch, and synchronize threads without the intervention of the process.

Disadvantages of User-level threads

1. User-level threads lack coordination between the thread and the kernel.
2. If a thread causes a page fault, the entire process is blocked.
Q:3) What are Multithreading Models ?
Ans). There are three types of multithreading models.
1. Many to many relationship.
2. Many to one relationship.
3. One to one relationship.

1. Many to Many Multithreading Model :-

In this model any number of user threads can be multiplied into equal or smaller numbers of kernel threads. Developers are
capable of creating multiple number of user threads and their corresponding Kernel threads can run in parallel on a
multiprocessor machine.The many to many model not only provides the best accuracy on concurrency but also when a
thread performs a blocking system call, the kernel schedules another thread for execution.

2. Many to One Multithreading Model :-


This model maps multiple user-level threads to one Kernel-level thread. When a blocking system call is made, the
thread library carries out thread management in the user library blocking the entire process. Multiple threads cannot run
in parallel only one thread can access the Kernel at a time.

3. One to One Multithreading Model :-


In this model, the user-level thread and the kernel-level thread share a one-to-one relationship. The concurrency provided
by this model is higher than the many-to-one model. It allows the parallel execution of multiple threads on
microprocessors.
Q:4) Tell Thread Libraries?
Ans).Thread libraries provide programmers with an API for creating and managing threads.Thread libraries may be
implemented either in user space or in kernel space. The former involves API functions implemented solely within user
space, with no kernel support. The latter involves system calls, and requires a kernel with thread library support.There are
three main thread libraries in use today:

1. POSIX Pthreads - may be provided as either a user or kernel library, as an extension to the POSIX standard.
2. Win32 threads - provided as a kernel-level library on Windows systems.
3. Java threads - Since Java generally runs on a Java Virtual Machine, the implementation of threads is based
upon whatever OS and hardware the JVM is running on, i.e. either Pthreads or Win32 threads depending on
the system.

Q:5) How to avoid Threads?


Ans). We can avoid by these ways.

1)-Single Process: Single Thread: Design your application to run in a single process with a single thread. This simplifies
the program's control flow but limits its ability to take advantage of multi-core processors.

2)-Multiple Processes: Instead of using threads, you can use multiple processes to achieve concurrency. Each process
runs independently with its own memory space. Inter-process communication (IPC) mechanisms, such as pipes or sockets,
can be used to exchange data between processes.
3)-Event-Driven Programming: Employ event-driven programming techniques where the application responds to external
events and triggers appropriate actions. This is common in graphical user interfaces (GUIs) and network servers.

4)-Fibers or Green Threads: Some programming languages and libraries offer lightweight alternatives to threads known
as fibers or green threads. These are user-level threads managed by a runtime library rather than the OS, which can be
less resource-intensive.

5)-Asynchronous Programming: Use asynchronous programming techniques and libraries that allow you to write code
that appears to be sequential but can perform non-blocking I/O operations efficiently. This is particularly useful in I/O-bound
applications.

6)-Parallel Processes: Divide your application into multiple processes that perform tasks in parallel. This approach is
commonly used in high-performance computing and scientific simulations.

7)-Message Passing: Utilize message-passing models to communicate between different parts of your application or
system. The Actor model is an example of this approach.

8)-Cooperative Multitasking: In a cooperative multitasking model, the application itself manages task switching rather
than relying on the OS scheduler. However, this can be error-prone and may lead to unresponsiveness if not implemented
carefully.

You might also like