[Autogenerated] as we've seen,
we can create threads using the create thread function and other
extended functions and that's fine for many scenarios.
However,
there are cases where we just need to run something which is constrained in
time on some other thread creating a threat has a cost.
Does the colonel object, there's the stack?
These things are not for free.
And so there is a mechanism called thread pools,
which allows us to say, hey, here's some work I'd like to do.
I want that to happen on a different thread,
not on my current thread, just do it on some other thread.
I don't really care which thread that is just do it and that's it.
And this is what thread pools are for.
The thread pool is the way to have a bunch of threats
waiting for work and once work is available,
they're going to run your code.
Some function really on some other thread that is part of your process.
And the basic idea is that the thread pool is dynamic,
The number of threats can increase or decrease based
on the load on the thread pool.
So the thread pool can have multiple clients working with it and
every process has a different thread pool,
which you can always use.
And the old function to use is called cues a work item which is
still available but there are newer APIs that have been available
since the vista days and we can create in fact more thread pools
known as private thread pools in the process because if you have
just a single thread pool,
it might be a bit problematic when you have different types of requests.
Perhaps some requests are more important than others.
If you just have a single thread pool,
then every request goes to the same thread pool and it's
going to be handled as quickly as possible.
But you don't have any way to provide any kind of hint as
a as to the importance of your code.
So if you create your own private thread pool,
you can target that thread pool, give it some different properties.
For example, different minimum maximum threats to use.
So that might be more appropriate for more complex scenarios.
The kernel object behind the scenes that manager thread
pools is called TP worker factory.
So thread pool worker Factory Worker Factory is the typical name you
would find in kernel documentation and there's a bunch of APIs a
fairly significant list of APIs that work with these new private
thread pools such as create thread pool,
create thread pool work and many others which of
course are all properly documented.
Let me show you one example of using a thread pool for primes counter case