By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,338 Members | 1,350 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,338 IT Pros & Developers. It's quick & easy.

threadpool

P: n/a
We are queueing stuff on the thread pool and what we are queueing gets done
pretty quick (the method returns fine) but yet its only allowed to run
around 25 times, is there anything I need to do to tell the threadpool that
my method is done running and the thread is to be disposed of?
Nov 13 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
memememe,

What do you mean that it is only allowed to run 25 times? Do you mean
that you can only have 25 concurrent activities at the same time?

The thread pool has a limit on the number of threads that can run at one
time from it. The max is determined by the number of processors, for each
processor on the machine, 25 threads are allowed in the thread pool.

Also, when your method is done, it will cause the thread pool thread to
be sent back to the pool, to be reused later. It should not die. This is
done to improve performance and reduce the overhead from initializing new
threads.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com
"memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
news:bo*********************@news1.central.cox.net ...
We are queueing stuff on the thread pool and what we are queueing gets done pretty quick (the method returns fine) but yet its only allowed to run
around 25 times, is there anything I need to do to tell the threadpool that my method is done running and the thread is to be disposed of?

Nov 13 '05 #2

P: n/a

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:ux*************@tk2msftngp13.phx.gbl...
memememe,

What do you mean that it is only allowed to run 25 times? Do you mean
that you can only have 25 concurrent activities at the same time?

The thread pool has a limit on the number of threads that can run at one time from it. The max is determined by the number of processors, for each
processor on the machine, 25 threads are allowed in the thread pool.

Also, when your method is done, it will cause the thread pool thread to be sent back to the pool, to be reused later. It should not die. This is
done to improve performance and reduce the overhead from initializing new
threads.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com
"memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
news:bo*********************@news1.central.cox.net ...
We are queueing stuff on the thread pool and what we are queueing gets

done
pretty quick (the method returns fine) but yet its only allowed to run
around 25 times, is there anything I need to do to tell the threadpool

that
my method is done running and the thread is to be disposed of?


sorry I should have been clearer.
We queue up a lot of work, more than 25, lets say 1k. We see the first 25
threads get executed, then they end, once they end no more work on the queue
gets executed, the threads in use are 25, the available threads are 0, but
our method ends and returns, so I am not sure what else we have to do to
tell the thread pool to go ahead and reuse the thread.
Nov 13 '05 #3

P: n/a

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:Ot**************@TK2MSFTNGP11.phx.gbl...
memememe,

How are you determining that the threads are not being reused? Once the work item is complete, the thread should go back to the pool.

Also, the thread pool is used by other parts of the framework, and it
doesn't just run the threads whenever. It also takes other factors into
consideration when deciding which items to perform work on.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
news:DU*********************@news1.central.cox.net ...

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:ux*************@tk2msftngp13.phx.gbl...
memememe,

What do you mean that it is only allowed to run 25 times? Do you mean that you can only have 25 concurrent activities at the same time?

The thread pool has a limit on the number of threads that can run at
one
time from it. The max is determined by the number of processors, for each processor on the machine, 25 threads are allowed in the thread pool.

Also, when your method is done, it will cause the thread pool
thread
to
be sent back to the pool, to be reused later. It should not die.
This is done to improve performance and reduce the overhead from initializing new threads.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com
"memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
news:bo*********************@news1.central.cox.net ...
> We are queueing stuff on the thread pool and what we are queueing

gets done
> pretty quick (the method returns fine) but yet its only allowed to run > around 25 times, is there anything I need to do to tell the threadpool that
> my method is done running and the thread is to be disposed of?
>
>

sorry I should have been clearer.
We queue up a lot of work, more than 25, lets say 1k. We see the first

25 threads get executed, then they end, once they end no more work on the

queue
gets executed, the threads in use are 25, the available threads are 0, but our method ends and returns, so I am not sure what else we have to do to
tell the thread pool to go ahead and reuse the thread.



well its a very simple program.
It queues up stuff to do on the threadpool (way more than 25) then it does
the stuff, I print out at the end of the method when its done processing,
and it exits fine, this happens for 25 times. There is nothing else running
on the system, its just a simple simple program, but I imagine once the
method is done running it should trhow the thread back on the queue? or do I
need to tell the thread pool that im done running that method?
Nov 13 '05 #4

P: n/a
memememe,

You don't have to tell the ThreadPool class anything when you are done,
it will know when you are done.

Can you post your code, and we can take a look at it?
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
news:i7*********************@news1.central.cox.net ...

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote in message news:Ot**************@TK2MSFTNGP11.phx.gbl...
memememe,

How are you determining that the threads are not being reused? Once the
work item is complete, the thread should go back to the pool.

Also, the thread pool is used by other parts of the framework, and it
doesn't just run the threads whenever. It also takes other factors into
consideration when deciding which items to perform work on.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
news:DU*********************@news1.central.cox.net ...

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com>

wrote
in message news:ux*************@tk2msftngp13.phx.gbl...
> memememe,
>
> What do you mean that it is only allowed to run 25 times? Do you
mean
> that you can only have 25 concurrent activities at the same time?
>
> The thread pool has a limit on the number of threads that can
run at one
> time from it. The max is determined by the number of processors,
for each
> processor on the machine, 25 threads are allowed in the thread pool.
>
> Also, when your method is done, it will cause the thread pool thread to
> be sent back to the pool, to be reused later. It should not die. This
is
> done to improve performance and reduce the overhead from
initializing new
> threads.
>
> Hope this helps.
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - ni**************@exisconsulting.com
>
>
> "memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
> news:bo*********************@news1.central.cox.net ...
> > We are queueing stuff on the thread pool and what we are queueing

gets > done
> > pretty quick (the method returns fine) but yet its only allowed to run > > around 25 times, is there anything I need to do to tell the threadpool > that
> > my method is done running and the thread is to be disposed of?
> >
> >
>
>
sorry I should have been clearer.
We queue up a lot of work, more than 25, lets say 1k. We see the first 25 threads get executed, then they end, once they end no more work on the

queue
gets executed, the threads in use are 25, the available threads are 0, but our method ends and returns, so I am not sure what else we have to do

to tell the thread pool to go ahead and reuse the thread.



well its a very simple program.
It queues up stuff to do on the threadpool (way more than 25) then it does
the stuff, I print out at the end of the method when its done processing,
and it exits fine, this happens for 25 times. There is nothing else

running on the system, its just a simple simple program, but I imagine once the
method is done running it should trhow the thread back on the queue? or do I need to tell the thread pool that im done running that method?

Nov 13 '05 #5

P: n/a

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:OG****************@tk2msftngp13.phx.gbl...
memememe,

You don't have to tell the ThreadPool class anything when you are done, it will know when you are done.

Can you post your code, and we can take a look at it?
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
news:i7*********************@news1.central.cox.net ...

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:Ot**************@TK2MSFTNGP11.phx.gbl...
memememe,

How are you determining that the threads are not being reused? Once
the
work item is complete, the thread should go back to the pool.

Also, the thread pool is used by other parts of the framework, and it doesn't just run the threads whenever. It also takes other factors
into consideration when deciding which items to perform work on.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
news:DU*********************@news1.central.cox.net ...
>
> "Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
> in message news:ux*************@tk2msftngp13.phx.gbl...
> > memememe,
> >
> > What do you mean that it is only allowed to run 25 times? Do you mean
> > that you can only have 25 concurrent activities at the same time?
> >
> > The thread pool has a limit on the number of threads that can run
at
> one
> > time from it. The max is determined by the number of processors,

for each
> > processor on the machine, 25 threads are allowed in the thread pool. > >
> > Also, when your method is done, it will cause the thread pool

thread
> to
> > be sent back to the pool, to be reused later. It should not die.

This
is
> > done to improve performance and reduce the overhead from initializing new
> > threads.
> >
> > Hope this helps.
> >
> >
> > --
> > - Nicholas Paldino [.NET/C# MVP]
> > - ni**************@exisconsulting.com
> >
> >
> > "memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
> > news:bo*********************@news1.central.cox.net ...
> > > We are queueing stuff on the thread pool and what we are queueing gets
> > done
> > > pretty quick (the method returns fine) but yet its only allowed
to
run
> > > around 25 times, is there anything I need to do to tell the

threadpool
> > that
> > > my method is done running and the thread is to be disposed of?
> > >
> > >
> >
> >
>
>
> sorry I should have been clearer.
> We queue up a lot of work, more than 25, lets say 1k. We see the
first 25
> threads get executed, then they end, once they end no more work on
the queue
> gets executed, the threads in use are 25, the available threads are

0, but
> our method ends and returns, so I am not sure what else we have to
do to > tell the thread pool to go ahead and reuse the thread.
>
>
well its a very simple program.
It queues up stuff to do on the threadpool (way more than 25) then it

does the stuff, I print out at the end of the method when its done processing, and it exits fine, this happens for 25 times. There is nothing else

running
on the system, its just a simple simple program, but I imagine once the
method is done running it should trhow the thread back on the queue? or

do I
need to tell the thread pool that im done running that method?



thanks for the help, i have a feeling there is something hanging the code
somewhere else, its not my code (bosses) so I cant post, nor do I know where
the problem might be, the thread thing I posted was the first thing I
noticed, I will check a little further. Thanks again
Nov 13 '05 #6

P: n/a
On Tue, 08 Jul 2003 18:32:46 GMT, "memememe"
<[rem]casolorz[rem]@hot[rem]mail.com> wrote:

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:Ot**************@TK2MSFTNGP11.phx.gbl...
memememe,

How are you determining that the threads are not being reused? Once

the
work item is complete, the thread should go back to the pool.

Also, the thread pool is used by other parts of the framework, and it
doesn't just run the threads whenever. It also takes other factors into
consideration when deciding which items to perform work on.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
news:DU*********************@news1.central.cox.net ...
>
> "Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com>

wrote
> in message news:ux*************@tk2msftngp13.phx.gbl...
> > memememe,
> >
> > What do you mean that it is only allowed to run 25 times? Do you

mean
> > that you can only have 25 concurrent activities at the same time?
> >
> > The thread pool has a limit on the number of threads that can runat > one
> > time from it. The max is determined by the number of processors, for

each
> > processor on the machine, 25 threads are allowed in the thread pool.
> >
> > Also, when your method is done, it will cause the thread poolthread > to
> > be sent back to the pool, to be reused later. It should not die.This
is
> > done to improve performance and reduce the overhead from initializing

new
> > threads.
> >
> > Hope this helps.
> >
> >
> > --
> > - Nicholas Paldino [.NET/C# MVP]
> > - ni**************@exisconsulting.com
> >
> >
> > "memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
> > news:bo*********************@news1.central.cox.net ...
> > > We are queueing stuff on the thread pool and what we are queueing

gets > > done
> > > pretty quick (the method returns fine) but yet its only allowed torun > > > around 25 times, is there anything I need to do to tell thethreadpool > > that
> > > my method is done running and the thread is to be disposed of?
> > >
> > >
> >
> >
>
>
> sorry I should have been clearer.
> We queue up a lot of work, more than 25, lets say 1k. We see the first25 > threads get executed, then they end, once they end no more work on the

queue
> gets executed, the threads in use are 25, the available threads are 0,but > our method ends and returns, so I am not sure what else we have to do to
> tell the thread pool to go ahead and reuse the thread.
>
>



well its a very simple program.
It queues up stuff to do on the threadpool (way more than 25) then it does
the stuff, I print out at the end of the method when its done processing,
and it exits fine, this happens for 25 times. There is nothing else running
on the system, its just a simple simple program, but I imagine once the
method is done running it should trhow the thread back on the queue? or do I
need to tell the thread pool that im done running that method?

My experience has been that if a thread is not available because they
are all in use, it throws some sort of exception (which may be handled
internally) and the request just goes away. It doesn't appear to
queue them up.

Of course, I could be wrong about that but that has been my
experience.

What I do is increment a counter each time I queue a threadpool
thread. When that thread finishes, I decrement the thread count. You
can use the Interlocked class to do this.

You get 25 threads per CPU, but some of them may be used by the
framework. So, before I queue up, I check to make sure I have several
threads left. If I don't, I go to sleep for a second or two, and keep
checking in a loop until I have enough threads available. When there
are enough, I queue up another thread.

Also, if you main thread ends while threadpool threads are running,
they will be aborted, so before I leave my routine, I make sure that
my threadcount is back to my start count. I just sleep again for a
few seconds in a loop and check the amount until it reaches zero.

The only catch is you have to make sure your threadpool thread doesn't
throw any exceptions that you don't handle. Otherwise, your
threadcount will not decrement and you'll "lose" threads.

Jonathan Schafer
Nov 13 '05 #7

P: n/a

"Jonathan Schafer" <jschafer@*NOSPAM*brierley.a.b.c.com> wrote in message
news:fe********************************@4ax.com...
On Tue, 08 Jul 2003 18:32:46 GMT, "memememe"
<[rem]casolorz[rem]@hot[rem]mail.com> wrote:

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrotein message news:Ot**************@TK2MSFTNGP11.phx.gbl...
memememe,

How are you determining that the threads are not being reused? Once
the
work item is complete, the thread should go back to the pool.

Also, the thread pool is used by other parts of the framework, and
it doesn't just run the threads whenever. It also takes other factors into consideration when deciding which items to perform work on.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
news:DU*********************@news1.central.cox.net ...
>
> "Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
> in message news:ux*************@tk2msftngp13.phx.gbl...
> > memememe,
> >
> > What do you mean that it is only allowed to run 25 times? Do you mean
> > that you can only have 25 concurrent activities at the same time?
> >
> > The thread pool has a limit on the number of threads that can runat
> one
> > time from it. The max is determined by the number of processors,
for each
> > processor on the machine, 25 threads are allowed in the thread pool. > >
> > Also, when your method is done, it will cause the thread pool

thread
> to
> > be sent back to the pool, to be reused later. It should not die.

This
is
> > done to improve performance and reduce the overhead from initializing new
> > threads.
> >
> > Hope this helps.
> >
> >
> > --
> > - Nicholas Paldino [.NET/C# MVP]
> > - ni**************@exisconsulting.com
> >
> >
> > "memememe" <[rem]casolorz[rem]@hot[rem]mail.com> wrote in message
> > news:bo*********************@news1.central.cox.net ...
> > > We are queueing stuff on the thread pool and what we are queueing

gets
> > done
> > > pretty quick (the method returns fine) but yet its only allowed torun
> > > around 25 times, is there anything I need to do to tell the

threadpool
> > that
> > > my method is done running and the thread is to be disposed of?
> > >
> > >
> >
> >
>
>
> sorry I should have been clearer.
> We queue up a lot of work, more than 25, lets say 1k. We see the
first25
> threads get executed, then they end, once they end no more work on
the queue
> gets executed, the threads in use are 25, the available threads are 0,but
> our method ends and returns, so I am not sure what else we have to do
to > tell the thread pool to go ahead and reuse the thread.
>
>


well its a very simple program.
It queues up stuff to do on the threadpool (way more than 25) then it

doesthe stuff, I print out at the end of the method when its done processing,
and it exits fine, this happens for 25 times. There is nothing else runningon the system, its just a simple simple program, but I imagine once the
method is done running it should trhow the thread back on the queue? or do Ineed to tell the thread pool that im done running that method?

My experience has been that if a thread is not available because they
are all in use, it throws some sort of exception (which may be handled
internally) and the request just goes away. It doesn't appear to
queue them up.

Of course, I could be wrong about that but that has been my
experience.

What I do is increment a counter each time I queue a threadpool
thread. When that thread finishes, I decrement the thread count. You
can use the Interlocked class to do this.

You get 25 threads per CPU, but some of them may be used by the
framework. So, before I queue up, I check to make sure I have several
threads left. If I don't, I go to sleep for a second or two, and keep
checking in a loop until I have enough threads available. When there
are enough, I queue up another thread.

Also, if you main thread ends while threadpool threads are running,
they will be aborted, so before I leave my routine, I make sure that
my threadcount is back to my start count. I just sleep again for a
few seconds in a loop and check the amount until it reaches zero.

The only catch is you have to make sure your threadpool thread doesn't
throw any exceptions that you don't handle. Otherwise, your
threadcount will not decrement and you'll "lose" threads.

Jonathan Schafer


god I had to read the whole code a few times before I noticed what he was
doing.
He was adding more threads to the queue inside of one of the threads that
was running and wasnt letting the thread exit until the threads that it
added were done, but they werent done until they could be executed but they
couldnt be executed because the 25 thread limit was already used. Simple
change fixed it all.
Nov 13 '05 #8

P: 3
Hi all

I have 2 threads, T1 and T1

Private Sub Button1_Click

Dim T1 As Thread = New System.Threading.Thread(AddressOf MyThreadTest)

Dim T2 As Thread = New Thread(AddressOf MyThreadLoad)

End sub


Public Sub MyThreadLoad()
'/// Some operation
End Sub

Public Sub MyThreadTest()
'///some operation
End Sub

In button click I need to keep T1 And T2 in a Thread Pool.

Please tell me how to do this...

Regards
Shivaraj
Jun 26 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.