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

Yes, because it's still in the thread pool. The post If I mark my thread pool callback as long-running, does it still count toward the thread pool thread limit? appeared first on The Old New Thing.

May 16, 2025 - 03:28
 0
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.

The post If I mark my thread pool callback as long-running, does it still count toward the thread pool thread limit? appeared first on The Old New Thing.