C++/VB - What does "persistent thread" mean.

Asked By Kürþat on 19-Nov-07 04:32 PM
Hi,

In MSDN documentation I see a term : "persistent thread". What does it mean?
In which conditions a thread becomes persistent?

Thanks in advance.


Pops replied on 19-Nov-07 06:13 PM
This is part of "Thread Pooling."

It basically means "Never dies."  Always available as in a pre-allocated
pool of "Worker Threads" waiting to do work for you. But they never die,
they are put to sleep when not busy and awaken when they are needed.
They only terminate with the POOL itself end, de-allocated, closed or exits.

Imagine you have connection system (lots of users connecting to you,
lots of mail being sent to you, etc), and you want to have 10 workers
always available to handle the connections.  Like a valet parking, and
you got 10 dudes always ready to park the incoming cars.

You might also prepare a small "growth" of threads, maybe 2-3 so that
when all 10 threads are busy (all the dudes are parking cars), you can
start the 11, 12, etc.  You can call the 10 workers persistent because
they are always available.

So on busy days with too many cars coming in (overloaded with internet
connections), you might have 2-3 part time valet dudes on call ready to
come in on a moment notice.

The full time dudes are PERSISTENT - because they are always there. The
others are not persistent, because the boss will tell them to go home
(thread dies) when they are not needed any more.

Some worker designs don't create the threads at all until they are
needed. But that can be inefficient if you know that you will have a
certain amount of persistent (constant) load.  When the data comes in,
all you need do to is PASS the data to the already running threads that
are not currently busy.

Make sense?

--
HLS
Vladimir Petter [MSFT] replied on 19-Nov-07 11:53 PM
A reason why you might want to have a thread pool's thread to be persistent
is if you issue overlapped IO or register for registry notification
(RegNotifyChangeKeyValue) from this thread. In windows when thread dies all
pending the IO it has issued will be canceled and to avoid that you can tell
thread pool to execute a work item that issues such an IO on a persistent
thread.
In general "persistent thread" is not only thread pool related. This term
can be used for the threads that are spawned by a user and would mean that
they stay around long enough to be safe to be used for assync IO, possibly
until the end of the process.

Vladimir.
Pops replied on 20-Nov-07 12:29 AM
Right, thanks for the follow up.

--
HLS
Kürsat replied on 20-Nov-07 03:36 AM
Both of your explanations are very clear. Thanks a lot.