deadlock એ એક સ્થિતિ છે જ્યાં બે કે વધુ threads દરેક એવા resource ની કાયમ રાહ જુએ છે જે બીજાં ધરાવે છે, તેથી કોઈ આગળ વધી શકતું નથી. તેને એકસાથે ચાર conditions ધરવાની જરૂર છે (Coffman conditions).
deadlock એ એક સ્થિતિ છે જ્યાં બે કે વધુ threads દરેક એવા resource ની કાયમ રાહ જુએ છે જે બીજાં ધરાવે છે, તેથી કોઈ આગળ વધી શકતું નથી. તેને એકસાથે ચાર conditions ધરવાની જરૂર છે (Coffman conditions).
કોઈ પણ એકને તોડો અને deadlock અશક્ય છે.
Thread 1 holds A, wants B ─┐
├─ circular wait → deadlock
Thread 2 holds B, wants A ─┘
# DEADLOCK: threads lock in opposite orders
def t1():
with lockA:
with lockB: ... # T1: A then B
def t2():
with lockB:
with lockA: ... # T2: B then A ← cycle!
# FIX: impose a global lock ordering (always A before B)
def safe():
with lockA:
with lockB: ... # everyone acquires in the same order
tryAcquire(timeout), back off અને retry — hold-and-wait ને તોડે છે.Deadlocks systems ને ચૂપચાપ freeze કરે છે — કોઈ crash નહીં, ફક્ત અટકેલી requests. ચાર conditions નામ આપવાં દર્શાવે છે કે તમે શા માટે તે થાય છે તે અંગે તર્ક કરી શકો છો અને targeted નિવારણ (સામાન્ય રીતે consistent lock ordering) પસંદ કરી શકો છો, locks છાંટીને આશા રાખવાને બદલે.
વિગતવાર જવાબો સાથે IT ઇન્ટરવ્યૂ પ્રશ્નોની લાઇબ્રેરી — જુનિયરથી સિનિયર સુધી.
દાન કરો