You are on page 1of 4

UNIVERSITY OF

SIALKOT

Name : Ali Imran Cheema Roll No. : 23201009-004


Program : MS CS Semester : 2nd
Session : Fall-2023 Subject : Advance Operating System
Assignment No. : 02 Submitted To : Prof. Dr Jabir Sb.

Assignment
Threads:
A thread, is the smallest unit of execution within a process. It represents a single,
sequential flow of control through a program's instructions. Threads are often
referred to as "lightweight processes" because they share the same resources as
their parent process, such as memory and open files. This makes them
significantly less resource-intensive than creating separate processes for each
concurrent task.

Benefits of Threads:

 Improved responsiveness:
o Threads enable programs to perform multiple tasks simultaneously,
improving responsiveness to user input and background activities.
For example, a web browser can download files while
simultaneously displaying content to the user.

 Increased concurrency:
o Threads allow programs to take advantage of multi-core processors,
leading to faster execution times for tasks that can be parallelized.

 Efficient resource utilization:


o Threads share resources with their parent process, minimizing
memory consumption and context switching overhead compared to
multiple processes.

 Modular design:
o Threads can be used to structure programs in a more modular and
maintainable way. Different tasks can be implemented as separate
threads, making the code more organized and easier to understand.
Multi-threading Models:

There are three main models for implementing multithreading:


1. Many-to-one model
2. One-to-one model
3. Many-to-many model

1. Many-to-one model:
In this model, there are multiple threads but only one CPU core available. The
operating system schedules threads onto the single core, allowing them to
execute concurrently in a time-sharing manner. This is the most common model
and is supported by most modern operating systems.

2. One-to-one model:
This model dedicates one thread to each available CPU core. This allows threads
to truly execute simultaneously, maximizing the potential for parallel processing.
However, this model requires careful synchronization to prevent race conditions
and other problems.
3. Many-to-many model:
This model allows for an arbitrary number of threads to be mapped to an
arbitrary number of CPU cores. This gives programmers the most flexibility but
also requires the most complex implementation and management strategies.

Additional Details:

Thread creation and termination:


Threads are created by processes using system calls provided by the
operating system. Once created, threads can be terminated by their parent
process or by themselves.
Thread synchronization:
When multiple threads access shared resources, it is essential to
synchronize their access to prevent data corruption and race conditions.
This is typically achieved using synchronization primitives like mutexes,
semaphores, and condition variables.
Thread scheduling:
The operating system is responsible for scheduling threads onto CPU
cores. This involves deciding which thread to run next and for how long.
Different scheduling algorithms exist, each with its own trade-offs in
terms of performance and fairness.

The End.

You might also like