OS Assignments No.2 PDF
OS Assignments No.2 PDF
SIALKOT
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.
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:
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:
The End.