{"id":111178,"date":"2025-05-14T07:00:00","date_gmt":"2025-05-14T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=111178"},"modified":"2025-05-14T09:24:28","modified_gmt":"2025-05-14T16:24:28","slug":"20250514-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20250514-00\/?p=111178","title":{"rendered":"If I mark my thread pool callback as long-running, does it still count toward the thread pool thread limit?"},"content":{"rendered":"<p>The Windows thread pool lets you declare that your callback is long-running. Depending on which interface you are using, this could be by calling <code>Set\u00adThreadpool\u00adCallback\u00adRuns\u00adLong<\/code>, or by calling <code>Callback\u00adMay\u00adRun\u00adLong<\/code>, or by passing the <code>WT_<wbr \/>EXECUTE\u00adLONG\u00adFUNCTION<\/code> flag to <code>Queue\u00adUser\u00adWork\u00adItem<\/code>.<\/p>\n<p>If you mark a callback as long-running, does it still count against the thread pool thread limit?<\/p>\n<p>Yes. A long-running thread pool callback still runs in the thread pool and still counts as a thread pool thread.<\/p>\n<p>Marking a flag as long-running is a hint to the thread pool manager that if it has other callbacks that are due, and it&#8217;s hoping that this callback will be finished soon so that it can use the thread to run those other callbacks, well, maybe it shouldn&#8217;t wait and should just go ahead and create another thread (assuming that the thread limit has not been reached).<\/p>\n<p>We saw a demonstration of this <a title=\"The importance of passing the WT_EXECUTELONGFUNCTION flag to QueueUserWorkItem\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20050722-15\/?p=34843\"> some time ago<\/a> where we showed that marking a callback as long-running informed the thread pool that it should create a new thread rather than wait for the existing callback to finish.<\/p>\n<p>But it&#8217;s still in the thread pool, and it counts as a thread pool thread. It&#8217;s not a &#8220;get out of thread pool free&#8221; card.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yes, because it&#8217;s still in the thread pool.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-111178","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Yes, because it&#8217;s still in the thread pool.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/111178","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=111178"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/111178\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=111178"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=111178"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=111178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}