OS Notes
OS Notes
Topic 6: View
There are 2 main views in an operating system. User and System
User view
1. Refers to the interface being used.
2. They are designed for one user to monopolize its resources, to maximize the work
that the user is performing.
3. In these cases, the operating system is designed mostly for ease of use, with some
attention paid to performance, and none paid to resource utilization.
System View
1. Viewed as a resource allocator also.
2. A computer system consists of many resources like hardware and software that
must be managed efficiently.
3. The operating system acts as the manager of the resources, decides between
conflicting requests, controls execution of programs etc
Definition:
A Critical Section is a segment of code where shared resources (like variables, memory, files)
are accessed or modified. The Critical Section Problem arises in concurrent programming when
processes must access shared resources without interference.
Objective:
The objective of solving the Critical Section Problem is to design a synchronization
mechanism so that only one process can enter its critical section at a time.
Challenges:
- Writing correct synchronization code without deadlocks or starvation.
- Maintaining performance by minimizing busy waiting.
Approaches to Solve:
- Software-based algorithms: Peterson’s, Dekker’s, Lamport’s bakery algorithm.
- Hardware support: Test-and-Set, Compare-and-Swap instructions.
- High-level constructs: Semaphores, Monitors, Mutexes.
Conclusion:
The Critical Section Problem is fundamental in process synchronization and solving it
correctly ensures the consistency and reliability of shared data in concurrent systems.
Definition:
Peterson’s Solution is a classical software-based algorithm for solving the critical section
problem for two processes. It ensures mutual exclusion, progress, and bounded waiting without
using hardware instructions.
Assumptions:
- Two processes: P0 and P1.
- Uses two shared variables:
1. flag[2]: Boolean array, where flag[i] = true means Pi wants to enter the critical section.
2. turn: An integer variable indicating whose turn it is to enter the critical section.
Algorithm:
The algorithm works as follows for each process Pi (i = 0 or 1):
- A process sets its flag[i] = true to indicate intent to enter the critical section.
- Then it sets the turn variable to give priority to the other process.
- If the other process also wants to enter (flag[1 - i] = true) and it’s its turn, the process waits.
- Otherwise, it enters the critical section.
- After exiting, it sets flag[i] = false to allow the other process to proceed.
Satisfies All Conditions:
1. Mutual Exclusion: Only one process can enter at a time.
2. Progress: A process not interested in entering does not block the other.
3. Bounded Waiting: Each process gets a fair chance to enter after some time.
Limitations:
- Works only for two processes.
- Relies on strict alternation and busy-waiting.
- Not suitable for modern CPUs with instruction reordering unless memory is marked volatile
or proper memory barriers are used.
Conclusion:
Peterson’s Algorithm is a simple and elegant solution to the critical section problem for two
processes. Though mostly educational, it illustrates the key principles of mutual exclusion using
only shared memory and basic instructions.