{"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-10-04T18:43:45","modified_gmt":"2026-10-04T16:43:45","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 um-t-etykiety\"><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> Right-click the process and select <em>Analyze wait chain<\/em>. The window shows what the selected process is waiting on.<\/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>Thread State<\/code> and <code>Thread Wait Reason<\/code>, that is, the thread state and the reason it is waiting. A value of 5 in Thread State means waiting.<\/li>\n\n\n\n<li><strong>Process dump and WinDbg.<\/strong> Save a dump of the hung process and go through the stacks 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 um-t-etykiety\"><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>SRWLOCK lock = SRWLOCK_INIT; AcquireSRWLockShared(&amp;lock); ReleaseSRWLockShared(&amp;lock);<\/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 a high server tick-rate<\/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 waits forever. Check it with the <em>Analyze wait chain<\/em>.<\/li>\n\n\n\n<li><strong>PerfMon.<\/strong> <code>Thread State<\/code> of the game threads does not stay at 5 (Wait) for the whole measurement.<\/li>\n\n\n\n<li><strong>Server.<\/strong> Average server tick-rate matching its configured value, 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:2.4rem 0;padding:1.6rem 1.6rem 1.7rem;border-radius:22px;border:1px solid color-mix(in srgb,#E7F6FF 12%,transparent);background:linear-gradient(160deg,color-mix(in srgb,#a100ff 13%,#04030a),#04030a 72%);}.um-cta h3{margin:0 0 .6rem;font-size:1.25rem;line-height:1.25;color:#fff;letter-spacing:-.01em;}.um-cta p{margin:0 0 1.1rem;font-size:.95rem;line-height:1.65;color:color-mix(in srgb,#E6EDF5 74%,transparent);}.um-cta-btn{display:inline-flex;align-items:center;gap:.5rem;padding:.8rem 1.4rem;border-radius:999px;text-decoration:none;font-weight:700;color:#fff;background:linear-gradient(135deg,#7A0010,color-mix(in srgb,#7A0010 66%,#000));border:1px solid color-mix(in srgb,#7A0010 66%,#E6EDF5);transition:box-shadow .3s ease,transform .3s ease;}.um-cta-btn:hover{transform:translateY(-1px);box-shadow:0 14px 34px -18px color-mix(in srgb,#a100ff 80%,transparent);}.um-cta-sub{display:block;margin-top:.9rem;font-size:.82rem;line-height:1.55;color:color-mix(in srgb,#E6EDF5 48%,transparent);}<\/style><div class=\"um-cta\"><h3>Frames dropping exactly when the fight starts?<\/h3><p>That drop lands in the one second that decides the round, and no graphics preset fixes it. We tune Windows, drivers and network remotely, and the BIOS together with you on a Discord call. You measure it yourself, in your own game, before and after, with us watching.<\/p><a class=\"um-cta-btn\" href=\"\/en\/pc-optimization\/\">See PC optimization <span class=\"arw\">&rarr;<\/span><\/a><span class=\"um-cta-sub\">Six months of support after the session. Not sure it is worth it? Ask for a free check on our Discord first.<\/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"},"_slim_seo_primary_term_category":0,"_slim_seo_primary_term_post_tag":0,"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":9,"href":"https:\/\/ultimatemove.eu\/en\/wp-json\/wp\/v2\/posts\/7563\/revisions"}],"predecessor-version":[{"id":8009,"href":"https:\/\/ultimatemove.eu\/en\/wp-json\/wp\/v2\/posts\/7563\/revisions\/8009"}],"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}]}}