Threadpool thread termination.

O

objectref

hi to all folks here,

let's say that i am using a threadpool and somehow, some threads in it just
stuck.
(endless loop or something like that).
So, if it receive a request to run for 25 times something that will stuck,
it simply will not
be able to take more request to dispatch as it will wait for a thread to
become available,
(due to 25 thread limit) something that in this example is not goint to
happen.

Am i able to identify these threads and somehow stop them so the ThreadPool
will be
able to take more request to dispatch ??



thanks a lot for any help,

objectref
 
R

Richard Grimes

objectref said:
hi to all folks here,

let's say that i am using a threadpool and somehow, some threads in
it just stuck.
(endless loop or something like that).

They're stuck. You had better write them so that they don't go into an
endless loop.

Officially a .NET thread is an abstract unit. In practice in .NET v 1.1
there is a one to one correspondence between .NET threads and OS
threads, and so conceivably you could use Win32 to terminate a thread
pool thread. However terminating a thread in Win32 is not a nice thing
to do because you'll lose data, and so it's best not to do that.

Basically there is no alternative other than making sure that the code
that you'll run on the thread pool thread does not go into an endless
loop. If it's code that yiu do not have access to the source then
metaphorically give them a kick up the arse.

Richard
 
N

Nicholas Paldino [.NET/C# MVP]

objectref,

No, there is no way to do this (and not using the thread pool will not
help either, since you will just end up sucking resources up by using
independent threads until your whole machine comes to a crawl).

Rather, you should identify why those threads are not terminating, and
fix that problem.
 
L

Larry Lard

objectref said:
hi to all folks here,

let's say that i am using a threadpool and somehow, some threads in it just
stuck.
(endless loop or something like that).
So, if it receive a request to run for 25 times something that will stuck,
it simply will not
be able to take more request to dispatch as it will wait for a thread to
become available,
(due to 25 thread limit) something that in this example is not goint to
happen.

Am i able to identify these threads and somehow stop them so the ThreadPool
will be
able to take more request to dispatch ??

How are you gonig to tell the difference between threads that are
'stuck' and threads that are 'taking a long time' ?
 
O

objectref

At first thank you all.
How are you gonig to tell the difference between threads that are
'stuck' and threads that are 'taking a long time' ?


Because the good ones will take no more than a few seconds to complete so i
can easily identify
the bad onew.
Anyway, i finaly used C# 2, i can use the SetMaxThreads so to add some more
threads to the pool and have the whole system
better monitor what is going on.

Again, thank you all!

objectref
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top