OS_Unit2
OS_Unit2
Race Condition
Critical Section
Explanation
1. int x = 10;
Process 1
1. // Process 1
2. int s = 10;
3. int u = 20;
4. x = s + u;
Process 2
Process 2
int s = 10;
int u = 20;
x = s - u;
1. Binary Semaphore
2. Counting Semaphore
Deadlock in OS
A process in operating system uses resources in the following
way.
1. Requests a resource
2. Use the resource
3. Releases the resource
A deadlock is a situation where a set of processes are
blocked because each process is holding a resource and
waiting for another resource acquired by some other process.
Consider an example when two trains are coming toward each
other on the same track and there is only one track, none of
the trains can move once they are in front of each other. A
similar situation occurs in operating systems when there are
two or more processes that hold some resources and wait for
resources held by other(s). For example, in the below diagram,
Process 1 is holding Resource 1 and waiting for resource 2
which is acquired by process 2, and process 2 is waiting for
resource 1.
Examples Of Deadlock
1. The system has 2 tape drives. P1 and P2 each hold one
tape drive and each needs another one.
2. Semaphores A and B, initialized to 1, P0, and P1 are in
deadlock as follows:
P0 executes wait(A) and preempts.
P1 executes wait(B).
Now P0 and P1 enter in deadlock.
P0 P1
wait(A);
wait(B)
wait(B); wait(A)
3. Assume the space is available for allocation of 200K
bytes, and the following sequence of events occurs.
P0
P1
3. No preemption
4. Circular Wait
Sr Deadlock Starvation
.
It also contains the information about all the instances of all the
resources whether they are available or being used by the
processes.
A resource can have more than one instance. Each instance will
be represented by a dot inside the rectangle.
Edges in RAG are also of two types, one represents assignment
and other represents the wait of a process for a resource. The
above image shows each of them.
Example
Mutual Exclusion
Circular Wait