O Sy Micro Project
O Sy Micro Project
MICRO PROJECT
Academic year: 2024-2025
Title of Micro Project:
Threads in Operating System
Program/Code: Computer Engineering (CO-2) Semester: FIFTH
Enrollment No.:
Certificate
Annexure – I
1.0 Rationale The introduction to operating systems is essential for understanding how computer
systems manage hardware and software resources efficiently. It provides a foundational framework
for grasping concepts like process management, memory allocation, and file systems. This
knowledge is crucial for developing effective software and optimizing performance, making it
integral for students pursuing careers in computer science and software engineering.
Sr.
Name of resources/Material Specifications Qty Remarks
No.
Processor: i3
1. Computer 1
RAM : 4.00 GB
2. Microsoft Word Word -2016 1
3. Printer Hp Laser Jet 1
https://www.academia.edu 1
4. Book/Site name
Annexure - III
Rubrics for Assessment of Micro-Project
2 Literature Survey .
Information Collection
3 Completion of the
Target as per project
proposal
5 Quality of Prototype/
Model/Content
6 Report Preparation
7 Presentation
8 Viva
1. Acknowledgement 01
2. Introduction 02
3. Benefits of Multithreading 03
4. Types of Threads 04
5. Multithreading Models 06
6. Conclusion 09
7. References 09
0
ACKNOWLEDGEMENT
1
Introduction
2
Benefits of Multithreading
1.Responsiveness :-
-Multithreading operating systems are interactive systems or applications. This
environment may allow program to execute or run continuously even if the part of it is
blocked or it may be performing a lengthy operation. This is known as responsiveness to
the user.
2. Resource Sharing:-
- Resources like code, data and file can be shared among all threads within a process.
- The advantage of sharing code and data is that it allows an application to have many
threads activity within the same address space of process.
3. Economy:-
- Allocating memory and resources for process creation is costly. Alternatively, because
threads share resources of the process to which they belong, it is more economical to
create and context switch threads.
- The overhead of creating and managing processes is much more than creating and
managing threads.
3
Types of threads
Threads are implemented in two ways:
1. User Level
2. Kernel Level
1.User Level Thread:
In a user thread, all of the work of thread management is done by the application and the
kernel is not aware of the existence of threads. The thread library contains code for
creating and destroying threads, for passing message and data between threads, for
scheduling thread execution and for saving and restoring thread contexts. The
application begins with a single thread and begins running in that thread
1. A user-level thread is a thread within a process which the OS does not know about.
2. In a user-level thread approach the cost of a context switch between threads is less
since the operating system itself does not need to be involved-no extra system calls are
required.
3. A user-level thread is represented by a program counter, registers, stack, and small
thread control block (TCB).
4. Programmers typically use a thread library to simplify management of threads within
a process.
5. Creating a new thread, switching between threads, and synchronizing threads are done
via function calls into the library. This provides an interface for creating and stopping
threads, as well as control over how they are scheduled.
Advantage of user level thread over Kernel level thread:
1. Thread switching does not require Kernel mode privileges.
2.User level thread can run on any operating system.
Disadvantages of user level thread :
1. In a typical operating system, most system calls are blocking.
2. Multithreaded application cannot take advantage of multiprocessing.
4
2. Kernel Level Thread:
In Kernel level thread, thread management done by the Kernel. There is no thread
management code in the application area. Kernel threads are supported directly by the
operating system. Any application can be programmed to be multithreaded. All of the
threads within an application are supported within a single process. The Kernel
maintains context information for the process as a whole and for individuals threads
within the process.
1. In systems that use kernel-level threads, the operating system itself is aware of each
individual thread.
2. Kernel threads are supported and managed directly by the operating system.
3. A context switch between kernel threads belonging to the same process requires only
the registers, program counter, and stack to be changed; the overall memory
management information does not need to be switched since both of the threads share
the same address space. Thus context switching between two kernel threads is slightly
faster than switching between two processes.
4. Kernel threads can be expensive because system calls are required to switch between
threads.
5. Also, since the operating system is responsible for scheduling the threads, the
application does not have any control over how its threads are managed.
Advantages of Kernel level thread:
1. Kernel can simultaneously schedule multiple threads from the same process on
multiple processes.
2. Kernel routines themselves can multithreaded.
Disadvantages:
1. Kernel threads are generally slower to create and manage than the user threads.
2. Transfer of control from one thread to another within same process requires a mode
switch to the Kernel.
5
multithreading models
Many systems provide support for both user and kernel threads, resulting in different
multithreading models.
1.One-to-One Model:
6
2.Many-to-One Model:
The many-to-one model maps many user level threads to one kernel thread.
Thread management is done in user space, so it is efficient, but the entire process
will block if a thread makes a blocking system call.
Only one thread can access the kernel at a time. Multiple threads are unable to run
in parallel on multiprocessors.
Example:- Green threads-a thread library available for Solaris uses this model, as
does GNU Portable Threads.
Advantages:
1. Totally portable.
2. Efficient system in terms of performance.
3. One kernel thread controls multiple user threads.
4. Mainly used in language system, portable Libraries.
Disadvantages:
1. Cannot take advantage of parallelism.
2. one block can block all user threads.
7
3.Many-to-Many Model:
Advantages:
1. Many threads can be created as per user's requirement.
2. Multiple kernel or equal to user threads can be created.
Disadvantages:
1. True concurrency cannot be achieved.
2. Multiple threads of kernel is an overhead for operating system.
3. Performance is less.
8
Conclusion:
1. Lightweight Nature: Threads share the same memory space within a process,
making them lighter than processes. This allows for faster context switching and
reduced overhead.
2. Concurrency: By enabling multiple threads to run concurrently, applications can
perform better, particularly in I/O-bound and CPU-bound tasks. This is crucial for
modern applications that require responsiveness.
3. Resource Sharing: Threads within the same process share resources, such as
memory and file descriptors, which simplifies communication and data sharing.
4. Synchronization Challenges: While sharing resources simplifies some aspects, it
also introduces challenges related to synchronization and data consistency.
Mechanisms like mutexes and semaphores are essential for avoiding race
conditions.
5. Thread Management: Operating systems provide various APIs for thread creation,
scheduling, and management, which developers can use to implement
multithreading in their applications.
6. Applications: Multithreading is widely used in web servers, real-time applications,
and GUI applications, enhancing performance and user experience.
In conclusion, threads are fundamental to the efficient operation of modern operating
systems, enabling enhanced performance, resource utilization, and responsiveness in
applications. However, careful management and synchronization are vital to prevent
issues arising from concurrent execution.
References:
OSY chapter 3 notes by prof. Amrita Rathod.
https://tutorialwing.com/user-level-thread-and-kernel-level-thread-with-example/
#google_vignette
https://www.geeksforgeeks.org/multi-threading-models-in-process-management/
https://www.scaler.com/topics/operating-system/threads-in-operating-system/
https://www.tutorialspoint.com/operating_system/os_multi_threading.htm