Deadlock

교착 상태

Jobs each wait for a resource held by the other and stop progressing.

···
html
<div class="v"><header><b>DEADLOCK CYCLE</b><span id="state"></span></header><main><div class="cycle"><b>A</b><span id="ab"></span><b>B</b><span id="ba"></span></div><div class="note" id="note"></div></main><footer>order locks consistently</footer></div>
css
.v{width:min(92vw,660px);height:min(86vh,310px);box-sizing:border-box;padding:clamp(9px,2.5vmin,18px);border:1px solid var(--line);border-radius:14px;background:var(--surface);display:flex;flex-direction:column;gap:7px;color:var(--fg);font:500 clamp(15px,3.2vmin,17px)/1.25 var(--font-sans, sans-serif)}.v header,.v footer{display:flex;justify-content:space-between;align-items:center;gap:8px;white-space:nowrap}.v header b{color:var(--accent);font-size:.9em}.v header span,.v footer{color:var(--muted);font-size:.82em}.v main{flex:1;min-height:0;position:relative;overflow:hidden}.v .mono{font-family:ui-monospace,SFMono-Regular,Consolas,monospace}.v .active{background:var(--accent)!important;color:var(--bg)!important;border-color:var(--accent)!important}.v .muted{opacity:.28} .cycle{height:62%;display:flex;align-items:center;justify-content:space-around;gap:5px}.cycle b{padding:12px;border:1px solid var(--line);border-radius:50%;font:700 1em ui-monospace,monospace}.cycle span{color:var(--accent);font-size:.85em}.note{text-align:center;color:var(--accent);font:600 .85em ui-monospace,monospace}
js
let n=0;function draw(){document.getElementById("ab").textContent=n?"holds L1 → waits L2":"acquire L1";document.getElementById("ba").textContent=n?"holds L2 → waits L1":"acquire L2";document.getElementById("note").textContent=n?"cycle closed: no progress":"opposite lock order";document.getElementById("state").textContent=n?"blocked":"running";n=1-n}draw();setInterval(draw,1400)

Deadlock occurs when job A holds lock 1 and waits for lock 2 while B holds lock 2 and waits for lock 1. Neither can advance without the other releasing its lock.

A consistent lock acquisition order prevents this cycle. A timeout can reveal the stall but does not by itself restore a consistent state.

When to use

Check for it when code or transactions acquire multiple locks.

Open as page ↗