Os Reporting
Os Reporting
In a multi-process operating system, multiple processes often need to access shared resources.
Synchronization mechanisms are crucial to prevent data corruption and ensure consistent
behavior when these processes interact.
A race condition occurs when the outcome of a program depends on the unpredictable
order in which multiple threads or processes1 execute.
Example: Imagine two processes trying to increment a shared counter. If they interleave
their operations, the final count might be incorrect.
The goal of synchronization is to ensure that only one process can be inside its critical
section at any given time.
o A mutex is a locking mechanism that allows only one thread to access a shared
resource at a time.
o A thread acquires the mutex before entering the critical section and releases it
afterward.
o Example:
o acquire(mutex);
o // Critical Section
o release(mutex);
Marcial
2. Semaphores:
o Types:
Tyron
3. Monitors:
o They provide2 automatic mutual exclusion, ensuring that only one thread can
execute within the monitor at a time.
o Condition variables are used for signaling and waiting within a monitor.
Ortinero
4. Condition Variables:
o Condition variables are used with monitors to allow threads to wait for specific
conditions to become true.
o wait() : a thread releases the monitor lock and waits on the condition variable.
o signal() : a thread notifies one waiting thread that the condition might be true.
Deadlock occurs when two or more processes are blocked indefinitely, each waiting for a
resource held by another process.3
1. Mutual Exclusion: Resources are non-sharable (only one process can use a resource at a
time).
2. Hold and Wait: A process holds at least one resource and is waiting to acquire additional
resources held by other processes.
3. No Preemption: Resources cannot be forcibly taken away from a process; they4 must be
released voluntarily.
4. Circular Wait: A circular chain5 of processes exists, where each process is waiting for a
resource held by the next process in the chain.6
1. Deadlock Prevention:
o Example: Require processes to request all resources at once (eliminates hold and
wait).
o Example: Impose a total ordering of resource requests, and require that each
process requests resources in an increasing order.
Ortinero
2. Deadlock Avoidance:
o The Banker's Algorithm, requires that the system knows in advance the
maximum resources a process might request.
Dale
o Recovery:
Resource preemption: Take resources away from processes and give them
to others.
Marcial
4. Deadlock Ignorance:
o Ignore deadlocks and hope they don't happen (used by many operating systems).
o When a deadlock occurs, the user is required to manually restart the system.
Proper resource management and careful design are essential to minimize the risk of
deadlocks.
Modern operating systems provide libraries and tools to support synchronization and
reduce the chance of deadlocks.
Five philosophers are sitting around a circular table, each with a plate of spaghetti.
If each philosopher picks up the left fork and waits for the right fork, a deadlock can
occur.