0% found this document useful (0 votes)
3 views4 pages

Os Reporting

The document discusses operating system synchronization and deadlocks, emphasizing the importance of synchronization mechanisms to prevent data corruption when multiple processes access shared resources. It outlines various synchronization techniques such as mutexes, semaphores, monitors, and condition variables, as well as the conditions for deadlock and strategies for handling it, including prevention, avoidance, detection, and recovery. Additionally, it highlights practical considerations for choosing synchronization methods and managing resources effectively to minimize deadlock risks.

Uploaded by

qwertyrhaast
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Os Reporting

The document discusses operating system synchronization and deadlocks, emphasizing the importance of synchronization mechanisms to prevent data corruption when multiple processes access shared resources. It outlines various synchronization techniques such as mutexes, semaphores, monitors, and condition variables, as well as the conditions for deadlock and strategies for handling it, including prevention, avoidance, detection, and recovery. Additionally, it highlights practical considerations for choosing synchronization methods and managing resources effectively to minimize deadlock risks.

Uploaded by

qwertyrhaast
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Lesson: Operating System Synchronization and Deadlocks

Marcial I. Synchronization: Ensuring Cooperation

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.

Tyron A. Race Conditions:

 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.

Ortinero B. Critical Sections:

 A critical section is a code segment where shared resources are accessed.

 The goal of synchronization is to ensure that only one process can be inside its critical
section at any given time.

Dale C. Synchronization Techniques:

1. Mutexes (Mutual Exclusion Locks):

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 A semaphore is a more general synchronization tool that manages access to a


limited number of resources.

o It maintains a counter that represents the number of available resources.


o wait() or P() operation decrements the counter, and signal() or V() operation
increments it.

o Types:

 Binary semaphore (counter = 0 or 1): Acts like a mutex.

 Counting semaphore (counter > 1): Controls access to multiple instances


of a resource.

Tyron

3. Monitors:

o Monitors are high-level synchronization constructs that encapsulate shared data


and the operations that can be performed on it.

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.

o broadcast() : notifies all waiting threads.

Dale II. Deadlocks: The Impasse

Deadlock occurs when two or more processes are blocked indefinitely, each waiting for a
resource held by another process.3

Marcial A. Necessary Conditions for Deadlock:

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

Tyron B. Deadlock Handling Strategies:

1. Deadlock Prevention:

o Aim to prevent one or more of the necessary conditions for deadlock.

o Example: Require processes to request all resources at once (eliminates hold and
wait).

o Example: Allow resource preemption.

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 Use algorithms to dynamically allocate resources in a way that avoids deadlock.

o Example: Banker's algorithm.

o The Banker's Algorithm, requires that the system knows in advance the
maximum resources a process might request.

Dale

3. Deadlock Detection and Recovery:

o Allow deadlocks to occur, detect them, and then recover.

o Detection: Build a wait-for graph to see if a cycle exists.

o Recovery:

 Process termination: Abort one or more deadlocked processes.

 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 Relies on the assumption that deadlocks are rare.

o When a deadlock occurs, the user is required to manually restart the system.

Tyron III. Practical Considerations:

 Choosing the appropriate synchronization mechanism depends on the specific


requirements of the application.

 Deadlock avoidance and detection algorithms can be complex and resource-intensive.

 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.

Ortinero Example Scenario: The Dining Philosophers Problem

 Five philosophers are sitting around a circular table, each with a plate of spaghetti.

 There is one fork between each pair of plates.7

 Philosophers need two forks to eat.

 If each philosopher picks up the left fork and waits for the right fork, a deadlock can
occur.

 This problem illustrates the challenges of resource allocation and synchronization.

You might also like