ਇੱਕ deadlock ਉਦੋਂ ਹੁੰਦਾ ਹੈ ਜਦੋਂ ਦੋ (ਜਾਂ ਵੱਧ) transactions ਇੱਕ ਲਾਕ ਰੱਖਦੇ ਹਨ ਜੋ ਦੂਸਰੇ ਨੂੰ ਚਾਹੀਦਾ ਹੈ, ਇਸ ਲਈ ਕੋਈ ਵੀ ਅੱਗੇ ਨਹੀਂ ਬੜ੍ਹ ਸਕਦਾ — ਉਹ ਇੱਕ ਦੂਸਰੇ ਦਾ ਹਮੇਸ਼ਾ ਸਾਹ ਲੁਕਾ ਕੇ ਫਸ ਜਾਂਦੇ ਹਨ। Databases deadlocks ਨੂੰ ਖੋਜਦੇ ਹਨ ਅਤੇ ਉਨ੍ਹਾਂ ਨੂੰ ਇੱਕ transaction ਨੂੰ abort ਕਰਕੇ ਹੱਲ ਕਰਦੇ ਹਨ ("victim"), ਜੋ ਮੁੜ ਕੋਸ਼ਿਸ਼ ਕਰਨਾ ਲਾਜ਼ਮੀ ਹੈ। Concurrent applications ਲਈ ਕਾਰਨ ਅਤੇ ਬਚਾਅ ਨੂੰ ਸਮਝਣਾ ਮਹੱਤਵਪੂਰਨ ਹੈ।
ਡੈੱਡਲਾਕ ਕਿਵੇਂ ਹੁੰਦਾ ਹੈ
Transaction A: locks row 1, then wants row 2
Transaction B: locks row 2, then wants row 1
→ A waits for B (to release row 2), B waits for A (to release row 1) → DEADLOCK
Neither can proceed; they're waiting on each other in a cycle.
; ;
accounts .. id; accounts .. id;
accounts .. id; accounts .. id;
