Sunday, November 17, 2024

What is a Deadlock

What is a Deadlock?

A deadlock occurs when two or more processes are unable to proceed because each is waiting for the other to release a resource.

Coffman Conditions (Necessary for Deadlock):

1. Mutual Exclusion: At least one resource is held in a non-shareable mode.

2. Hold and Wait: A process is holding at least one resource and is waiting for additional resources held by others.

3. No Preemption: Resources cannot be forcibly taken from a process holding them.

4. Circular Wait: A circular chain of processes exists, where each process is waiting for a resource held by the next process in the chain.

Deadlock Example with Transactions:

• Transaction A:

• Holds payments resource.

• Requests orders resource.

• Transaction B:

• Holds orders resource.

• Requests payments resource.

• This forms a circular wait between the two transactions.

Steps Demonstrated:

1. Transaction A locks payments.

2. Transaction B locks orders.

3. Transaction A requests orders but is blocked.

4. Transaction B requests payments but is blocked.

This cycle causes a deadlock.

Deadlock Recovery Methods:

1. Select a victim: Choose a process to terminate or roll back.

2. Rollback: Undo part of the process to break the deadlock.

Deadlock Prevention Techniques:

1. Request resources in a strictly increasing order.

2. Timeout or rollback processes holding resources for too long.

3. Banker’s Algorithm: A technique to avoid deadlocks by simulating resource allocation.

No comments:

Post a Comment

Understanding Essential DNS Record Types for Web Administrators

  Understanding Essential DNS Record Types for Web Administrators Introduction The Domain Name System (DNS) acts as the backbone of the inte...