Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Joriel B.

Moran BSIT-201C

1. Describe the deadlock scenario illustrated above based on your understanding

It shows a deadlock scenario involving two processes, P and Q, and two resources, A and B. Deadlock is a
situation where two or more processes are waiting for resources that are held by each other. In this case,
process P is holding resource A and waiting for resource B, while process Q is holding resource B and
waiting for resource A.

2. What do you think would happen if both Process P and Q need to get the same resource?

If both processes need the same resource, they can deadlock. This happens when one process acquires
the resource and the other process is blocked waiting for it. The first process cannot continue until it
acquires the second resource, and the second process cannot continue until it acquires the first
resource. This creates a deadlock situation where neither process can make any progress.

3. Which concurrency mechanism would you suggest that might prevent the deadlock situation
above? Rationalize your answer

One concurrency mechanism that can be used to prevent deadlock is mutual exclusion. Mutual exclusion
ensures that only one process can access a shared resource at a time. This can be achieved using locks or
semaphores.

In the case of the deadlock scenario shown in the image, we could prevent deadlock by using a lock to
protect each resource. For example, we could create a lock for resource A and a lock for resource B.
When a process needs to access resource A, it would first acquire the lock for resource A. Once the
process is finished with resource A, it would release the lock. When a process needs to access resource
B, it would first acquire the lock for resource B. Once the process is finished with resource B, it would
release the lock.

By using locks to protect each resource, we can ensure that only one process can access a resource at a
time. This will prevent deadlock from occurring because no process will be able to hold one resource and
wait for another resource that is held by another process.

4. Define in detail the Execution Paths 2 to 6. Example: Execution Path 1 – Process Q acquires Resource
B and then Resource A. Process Q then releases Resource B and A, respectively.

Execution Path 2: Process P acquires resource A and then resource B. Process P then releases resource B
and A, respectively.

Execution Path 3: Process P acquires resource A and then tries to acquire resource B, but is blocked
because process Q is holding it.

Execution Path 4: Process Q acquires resource B and then tries to acquire resource A, but is blocked
because process P is holding it.

Execution Path 5: Process P releases resource A and then process Q acquires it. Process Q then releases
resource B and process P acquires it.

Execution Path 6: Process Q releases resource B and then process P acquires it. Process P then releases
resource A and process Q acquires it.
5. Do Execution Paths 3 and 4 encompass the first three conditions for a deadlock to occur? Explain
your answer.

Yes, Execution Paths 3 and 4 encompass the first three conditions for a deadlock to occur:

Mutual exclusion: Both processes are holding at least one resource and waiting for at least one other
resource.

Hold and wait: Process P is holding resource A and waiting for resource B, while process Q is holding
resource B and waiting for resource A.

No preemption: Resources cannot be forcibly taken away from a process.

The only condition that is not met in Execution Paths 3 and 4 is the circular wait condition. However, if
both processes continue to wait for the resources they need, they will eventually enter a circular wait
and deadlock will occur.

6. If you are to implement deadlock prevention before the processes above reach the critical section,
would it be an indirect method or an indirect method? Why?

Indirect Method Deadlock prevention methods that work by eliminating any of the four necessary
conditions for deadlock are considered indirect methods. In this case, we would be preventing the hold
and wait condition by requiring processes to release all resources before acquiring a new one. This is
considered an indirect method because it does not directly address the critical section, which is the root
cause of deadlock.

7. Which deadlock avoidance approach would you suggest for the given situation above and why?

The Banker's algorithm is a deadlock avoidance approach that works by tracking the resource allocation
and request of each process. It uses this information to determine whether a request can be granted
without causing deadlock. In the given situation above, the Banker's algorithm could be used to prevent
deadlock by ensuring that no process is granted a resource that would cause it to enter a circular wait

8. Would you agree that deadlock is relative to the number of processes and available resources in an
operating system? Why or why not?

Deadlock is relative to the number of processes and available resources in an operating system because
it requires all four of the following conditions to occur simultaneously:

Mutual exclusion: At least one resource must be held in a mutually exclusive manner.

Hold and wait: At least one process must be holding at least one resource and waiting for at least one
other resource.

No preemption: Resources cannot be forcibly taken away from a process.

Circular wait: There must be a circular chain of two or more processes, each of which is waiting for a
resource held by the next process in the chain. If any of these conditions are not met, then deadlock
cannot occur. For example, if there are more resources available than processes, then there is no need
for any process to wait for a resource, and therefore deadlock cannot occur.

9. If you are asked to reconstruct the progress diagram above to eliminate the critical section, which is
the deadlock-inevitable region, which aspect(s) or area(s) would you modify? Explain how the
modification eliminates the deadlock.

Modify the progress diagram to eliminate the critical section.

The critical section is the deadlock-inevitable region because it is where processes acquire and release
resources. To eliminate the critical section, we would need to modify the progress diagram so that
processes acquire and release resources in a different way. For example, we could use a two-phase
locking protocol, where processes first acquire all of the resources they need before they start executing
their critical section. This would prevent processes from getting into a situation where they are waiting
for resources that are held by each other.

You might also like