{"id":7563,"date":"2026-08-14T23:30:04","date_gmt":"2026-08-14T21:30:04","guid":{"rendered":"https:\/\/ultimatemove.eu\/deadlocki-w-windows-jak-ich-unikac-i-co-z-nich-zrobic-aby-twoje-e-sportowe-sesje-byly-plynniejsze\/"},"modified":"2026-08-21T23:05:20","modified_gmt":"2026-08-21T21:05:20","slug":"deadlocks-in-windows","status":"publish","type":"post","link":"https:\/\/ultimatemove.eu\/en\/deadlocks-in-windows\/","title":{"rendered":"Deadlocks in Windows: how to spot them and how to avoid them"},"content":{"rendered":"<div  class=\"wp-block-ultimate-post-image ultp-block-d87f06\"><div class=\"ultp-block-wrapper\"><figure class=\"ultp-image-block-wrapper\"><div class=\"ultp-image-block ultp-image-block-none\"><img decoding=\"async\"  class=\"ultp-image\"  alt=\"Dark UltimateMove banner reading When two threads wait forever with two blocked locks in a cycle\"  src=\"https:\/\/ultimatemove.eu\/wp-content\/uploads\/2026\/08\/windows-deadlocks-header.avif\" \/><\/div><\/figure><\/div><\/div>\n\n\n<p class=\"wp-block-paragraph\">The game freezes for two seconds in the middle of a duel. FPS reads 240 and the picture stands still. The server drops a tick even though the CPU is idling. Behind some of these cases sits a deadlock, a thread lock-up. This article shows how to recognise them and how to get rid of them.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What a deadlock is<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Deadlock from Valve&#8230; we write about it a lot - unfortunately this time we mean something less colourful - a system deadlock. It happens when two threads wait on each other for resources they have already locked. Thread A holds lock 1 and waits for lock 2. Thread B holds lock 2 and waits for lock 1. Neither gives way, so both stand still until the process dies.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">From the player perspective there is no load to see. The CPU has headroom, the GPU has headroom, and still nothing moves.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Where it hurts in games and on servers<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Area<\/th><th>Example in games<\/th><th>Consequences<\/th><\/tr><\/thead><tbody><tr><td><strong>Client<\/strong><\/td><td>A lock on the render thread while a frame waits for network data<\/td><td>A stutter or a black screen at high FPS<\/td><\/tr><tr><td><strong>Server<\/strong><\/td><td>Game logic waits for a result from another thread, for example from AI<\/td><td>Delays in state synchronisation, a drop in tick-rate<\/td><\/tr><tr><td><strong>Matchmaking<\/strong><\/td><td>The player matching algorithm waits for data locked by another process<\/td><td>Longer queues, more timeouts when a map is assigned<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">How to detect deadlocks in Windows<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Task Manager, Details tab.<\/strong> The <em>Blocked<\/em> column shows processes stopped by a lock.<\/li>\n\n\n\n<li><strong>Process Explorer (Sysinternals).<\/strong> W <code>Open Handles<\/code> look for the names of mutexes, files and COM objects held too long.<\/li>\n\n\n\n<li><strong>PerfMon.<\/strong> Counters <code>MutexWait Time<\/code> and <code>ThreadTimeInState(4)<\/code>, that is, time spent in the waiting state.<\/li>\n\n\n\n<li><strong>ETW and Debugging Tools.<\/strong> Enable the <em>Microsoft-Windows-Debugger<\/em> provider and go through the stacks in WinDbg with the command <code>~* k<\/code>. Deadlocked threads sit on the same <code>WaitForSingleObject<\/code> for the whole dump.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Where they come from<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A different lock ordering in different threads<\/li>\n\n\n\n<li>An I\/O operation performed inside a critical section<\/li>\n\n\n\n<li>Mixing COM apartments, that is, synchronous calls between STA and MTA<\/li>\n\n\n\n<li>Priority inversion, when a low priority thread holds a lock a high priority thread needs<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How to avoid them<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Strategy<\/th><th>What to do<\/th><th>Example code (C++\/Win32)<\/th><\/tr><\/thead><tbody><tr><td><strong>Lock ordering<\/strong><\/td><td>Settle on one lock ordering and stick to it across the whole codebase, for example alphabetically by name.<\/td><td><code>void AcquireAll(std::vector&lt;MutexHandle&gt;&amp; locks){ std::sort(locks.begin(), locks.end(), [](auto&amp; a, auto&amp; b){ return a.name &lt; b.name; }); for(auto&amp; l : locks) WaitForSingleObject(l.handle, INFINITE); }<\/code><\/td><\/tr><tr><td><strong>Try-lock with a timeout<\/strong><\/td><td>If you do not get the lock within the given time, release what you already hold and start again.<\/td><td><code>bool TryLock(MutexHandle&amp; m){ return WaitForSingleObject(m.handle, 500) == WAIT_OBJECT_0; }<\/code><\/td><\/tr><tr><td><strong>Do not block the main thread<\/strong><\/td><td>Keep the UI and render threads free. Do I\/O asynchronously.<\/td><td><code>\/\/ asynchronous read via an overlapped structure ReadFile(hFile, buf, size, NULL, &amp;ov); \/\/ no blocking calls in the critical section<\/code><\/td><\/tr><tr><td><strong>SRWLOCK instead of a mutex<\/strong><\/td><td>Many readers work in parallel, and only writes get exclusivity.<\/td><td><code>std::shared_mutex srw; AcquireShared(srw); ReleaseShared(srw);<\/code><\/td><\/tr><tr><td><strong>COM apartment hygiene<\/strong><\/td><td>UI in STA, server logic in MTA. Avoid synchronous calls between them.<\/td><td><code>CoInitializeEx(NULL, COINIT_MULTITHREADED);<\/code><\/td><\/tr><tr><td><strong>A watchdog that detects cycles<\/strong><\/td><td>Check the wait graph every few seconds. A cycle means a deadlock, so restart the thread or the application.<\/td><td>Depth-first search (DFS) over the <em>wait-for graph<\/em><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Concrete cases from game servers<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Problem<\/th><th>Solution<\/th><\/tr><\/thead><tbody><tr><td><strong>Matchmaking waits on the database (SQL Server)<\/strong><\/td><td>Shorten transactions, review query plans, enable <code>READ COMMITTED SNAPSHOT<\/code>.<\/td><\/tr><tr><td><strong>The AI thread holds a mutex for the whole computation<\/strong><\/td><td>Move the computation outside the critical section and release the lock right after writing the result.<\/td><\/tr><tr><td><strong>Game state synchronisation at tick-rate 128<\/strong><\/td><td>Use <code>SpinLock<\/code> instead of <code>Mutex<\/code>, but keep the critical section within a few microseconds.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">What the player gets out of it<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Shorter delays. Removing a deadlock takes the milliseconds you will not see in any benchmark off the server response time.<\/li>\n\n\n\n<li>A stable session. The client stops freezing at random moments, and the FPS graph stops having holes in it.<\/li>\n\n\n\n<li>Better scalability. The server handles more players on the same hardware.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Checklist after rolling out the changes<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Task Manager.<\/strong> Under heavy load no process sits in state <em>Blocked<\/em>.<\/li>\n\n\n\n<li><strong>PerfMon.<\/strong> <code>MutexWait Time<\/code> below 5 ms for client applications.<\/li>\n\n\n\n<li><strong>Server.<\/strong> Average tick-rate at least 128, with no dropped ticks.<\/li>\n\n\n\n<li><strong>Profiler.<\/strong> Intel VTune or AMD uProf shows no long critical sections.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">So what you need?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A deadlock consumes no resources, so you will not see it on any load graph. Look for it where the threads stand still: in Task Manager, in Process Explorer and in stack dumps.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Three habits are enough to stop producing them. Settle on one lock ordering. Keep I\/O out of critical sections. On the server reach for lock-free structures, and on the client for asynchronous I\/O. You see the result in the ping, in frame stability and in the number of players the server holds without choking.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Related articles<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"\/en\/windows-gaming-optimization\/\"><strong>Windows gaming optimisation<\/strong><\/a><\/li>\n\n\n\n<li><a href=\"\/en\/valorant-desync-fps-packet-rate\/\"><strong>Valorant: too much FPS breaks the client tickrate<\/strong><\/a><\/li>\n\n\n\n<li><a href=\"\/en\/10-best-ways-to-improve-fps-in-games-for-2026\/\"><strong>10 Best Ways to Improve FPS in games for 2026<\/strong><\/a><\/li>\n\n\n\n<li><a href=\"\/en\/official-list-of-useful-gaming-tools\/\"><strong>The official list of useful gaming tools<\/strong><\/a><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n<style id=\"um-cta-opt\">.um-cta{margin:34px 0;padding:22px 22px 24px;border-radius:10px;border:1px solid #3a3357;background:linear-gradient(180deg,#141024 0%,#1c1631 100%);}.um-cta h3{margin:0 0 8px;font-size:19px;line-height:1.3;}.um-cta p{margin:0 0 14px;font-size:14.5px;line-height:1.65;color:#b6aed4;}.um-cta-btn{display:inline-block;padding:12px 22px;border-radius:8px;text-decoration:none;background:linear-gradient(135deg,#7A0010 0%,#a8001a 55%,#a100ff 140%);color:#ffeef1;border:2px solid rgba(155,147,236,.75);box-shadow:0 0 20px rgba(161,0,255,.4),inset 0 0 0 1px rgba(255,255,255,.06);font-weight:600;transition:box-shadow .3s ease,transform .3s ease;}.um-cta-btn:hover{box-shadow:0 0 30px rgba(161,0,255,.65),inset 0 0 0 1px rgba(255,255,255,.1);transform:translateY(-1px);}.um-cta-sub{display:block;margin-top:12px;font-size:12.5px;color:#8f86b8;}<\/style><div class=\"um-cta\"><h3>Frames dropping exactly when the fight starts?<\/h3><p>Deadlock leans hard on the CPU during team fights, which is the moment your frames fall and your aim stops landing. We tune your PC remotely: Windows, drivers, BIOS and network. You can measure it yourself before and after, in the game, with us watching. We do not stop you.<\/p><a class=\"um-cta-btn\" href=\"\/en\/pc-optimization\/\">See PC optimization<\/a><span class=\"um-cta-sub\">Satisfaction guarantee and six months of support after the session. Not sure if it is worth it? Ask for a free check on our Discord.<\/span><\/div>","protected":false},"excerpt":{"rendered":"<p>A thread deadlock consumes no resources, yet it can freeze the game client and take a tick off the server. How to find them in Windows, and which habits stop you producing them.<\/p>","protected":false},"author":5,"featured_media":7625,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"slim_seo":{"facebook_image":"https:\/\/ultimatemove.eu\/wp-content\/uploads\/2026\/08\/windows-deadlocks-header.avif","twitter_image":"https:\/\/ultimatemove.eu\/wp-content\/uploads\/2026\/08\/windows-deadlocks-header.avif","canonical":"https:\/\/ultimatemove.eu\/deadlocks-in-windows\/","title":"Deadlocki w Windows: jak je wykry\u0107 i jak ich unika\u0107 - UltimateMove","description":"Zakleszczenie w\u0105tk\u00f3w nie zu\u017cywa zasob\u00f3w, a potrafi zamrozi\u0107 klienta gry i zdj\u0105\u0107 tick z serwera. Jak je znale\u017a\u0107 w Windows i jakimi nawykami przesta\u0107 je produkowa"},"footnotes":""},"categories":[153],"tags":[775,179,209,821],"class_list":["post-7563","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-gaming-research","tag-deadlock","tag-esports-performance","tag-gaming-optimization","tag-windows"],"_links":{"self":[{"href":"https:\/\/ultimatemove.eu\/en\/wp-json\/wp\/v2\/posts\/7563","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ultimatemove.eu\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ultimatemove.eu\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ultimatemove.eu\/en\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ultimatemove.eu\/en\/wp-json\/wp\/v2\/comments?post=7563"}],"version-history":[{"count":7,"href":"https:\/\/ultimatemove.eu\/en\/wp-json\/wp\/v2\/posts\/7563\/revisions"}],"predecessor-version":[{"id":7634,"href":"https:\/\/ultimatemove.eu\/en\/wp-json\/wp\/v2\/posts\/7563\/revisions\/7634"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ultimatemove.eu\/en\/wp-json\/wp\/v2\/media\/7625"}],"wp:attachment":[{"href":"https:\/\/ultimatemove.eu\/en\/wp-json\/wp\/v2\/media?parent=7563"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ultimatemove.eu\/en\/wp-json\/wp\/v2\/categories?post=7563"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ultimatemove.eu\/en\/wp-json\/wp\/v2\/tags?post=7563"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}