May 14th, 2025

If I mark my thread pool callback as long-running, does it still count toward the thread pool thread limit?

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 Set­Threadpool­Callback­Runs­Long, or by calling Callback­May­Run­Long, or by passing the WT_EXECUTE­LONG­FUNCTION flag to Queue­User­Work­Item.

If you mark a callback as long-running, does it still count against the thread pool thread limit?

Yes. A long-running thread pool callback still runs in the thread pool and still counts as a thread pool thread.

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’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’t wait and should just go ahead and create another thread (assuming that the thread limit has not been reached).

We saw a demonstration of this some time ago 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.

But it’s still in the thread pool, and it counts as a thread pool thread. It’s not a “get out of thread pool free” card.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments