Detection: build a resource allocation graph or a wait-for graph and look for cycles (with single-instance resources a cycle means deadlock; with multiple instances, use a detection algorithm similar to Banker's).
Recovery: terminate one or all deadlocked processes, or preempt resources and roll back a process to a checkpoint, choosing victims by priority, progress and cost; avoid always choosing the same victim, which causes starvation.
Many general-purpose systems simply ignore the problem (the ostrich approach) and rely on developers; databases detect deadlocks and abort one transaction.
Loading…