PC Review


Reply
Thread Tools Rate Thread

Maximum number of threads in a process

 
 
Edward Diener
Guest
Posts: n/a
 
      21st Feb 2005
Is there an operating system limit to the number of threads in a process ? A
test program I was writing created approximately 105 threads for a process
( many unused because of some thread pool code ), and an out of memory error
occurred when an attempt was made to create more threads. Since I do not
believe that the application was using much memory compared to the nearly 1
GIG of total virtual memory, I assume that the out of memory exception had
to do with exceeding a thread creation limit for a single process.


 
Reply With Quote
 
 
 
 
William DePalo [MVP VC++]
Guest
Posts: n/a
 
      22nd Feb 2005
"Edward Diener" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Is there an operating system limit to the number of threads in a process ?


No. The limiting factor usually turns out to be memory. Every thread by
_default_ gets a 1MB stack. Sooner or later you run out of contiguous
virtual address space.

I am surprised though that you hit the wall at 105. I have seen native
programs can several hundred more threads before giving up the ghost. I
haven't seen any reports about likely limits under .Net

<aside>
That said, where high performance is required, it is rarely a good idea to
have so many threads if all of them can compete for the processor. On the
native side of things, a thread pool and an I/O completion port scale
better.
</aside>

Regards,
Will


 
Reply With Quote
 
cody
Guest
Posts: n/a
 
      22nd Feb 2005
You can set a smaller stack size for your threads maybe that helps.
But in general if you have lots of threads thread pooling is the best
solution.

"Edward Diener" <(E-Mail Removed)> schrieb im Newsbeitrag
news:#(E-Mail Removed)...
> Is there an operating system limit to the number of threads in a process ?

A
> test program I was writing created approximately 105 threads for a process
> ( many unused because of some thread pool code ), and an out of memory

error
> occurred when an attempt was made to create more threads. Since I do not
> believe that the application was using much memory compared to the nearly

1
> GIG of total virtual memory, I assume that the out of memory exception had
> to do with exceeding a thread creation limit for a single process.
>
>



 
Reply With Quote
 
Edward Diener
Guest
Posts: n/a
 
      22nd Feb 2005
"William DePalo [MVP VC++]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Edward Diener" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> Is there an operating system limit to the number of threads in a process
>> ?

>
> No. The limiting factor usually turns out to be memory. Every thread by
> _default_ gets a 1MB stack. Sooner or later you run out of contiguous
> virtual address space.
>
> I am surprised though that you hit the wall at 105. I have seen native
> programs can several hundred more threads before giving up the ghost. I
> haven't seen any reports about likely limits under .Net


I realized that the number of threads created was closer to 300 rather than
100. Each thread pool was creating 25 threads. I have since corrected the
test program I am running to use a single thread pool rather than the dozen
or so I was previously using, and everything runs fine now. Thanks for your
explanation about each thread using a 1MB stack. That would explain why I
ran out of memory.

>
> <aside>
> That said, where high performance is required, it is rarely a good idea to
> have so many threads if all of them can compete for the processor. On the
> native side of things, a thread pool and an I/O completion port scale
> better.
> </aside>


There was a thread pool but it was encapsulated in a class which I was
instantiating numerous times even though I really only needed one instance
of the class.


 
Reply With Quote
 
Brian Gideon
Guest
Posts: n/a
 
      22nd Feb 2005
Edward,

Are you aware that .NET has a built-in thread pool available. You made
it sound as if you've created your own and that maybe fine if there are
special requirements. I just thought I'd give you a friendly heads-up
in case you were not aware of it.

Brian

Edward Diener wrote:
> I realized that the number of threads created was closer to 300
> rather than 100. Each thread pool was creating 25 threads. I have
> since corrected the test program I am running to use a single
> thread pool rather than the dozen or so I was previously using,
> and everything runs fine now. Thanks for your explanation about
> each thread using a 1MB stack. That would explain why I ran out
> of memory.
>


 
Reply With Quote
 
Edward Diener
Guest
Posts: n/a
 
      23rd Feb 2005
"Brian Gideon" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Edward,
>
> Are you aware that .NET has a built-in thread pool available. You made
> it sound as if you've created your own and that maybe fine if there are
> special requirements. I just thought I'd give you a friendly heads-up
> in case you were not aware of it.


Yes, I was aware of it and the decision to use another thread pool was not
mine. Thanks, nonetheless for the heads-up.

>
> Brian
>
> Edward Diener wrote:
>> I realized that the number of threads created was closer to 300
>> rather than 100. Each thread pool was creating 25 threads. I have
>> since corrected the test program I am running to use a single
>> thread pool rather than the dozen or so I was previously using,
>> and everything runs fine now. Thanks for your explanation about
>> each thread using a 1MB stack. That would explain why I ran out
>> of memory.
>>

>



 
Reply With Quote
 
Edward Diener
Guest
Posts: n/a
 
      23rd Feb 2005
"cody" <(E-Mail Removed)> wrote in message
news:eNlYK%(E-Mail Removed)...
> You can set a smaller stack size for your threads maybe that helps.
> But in general if you have lots of threads thread pooling is the best
> solution.


Thanks for the info about setting a smaller stack size. I will look into
this.

>
> "Edward Diener" <(E-Mail Removed)> schrieb im Newsbeitrag
> news:#(E-Mail Removed)...
>> Is there an operating system limit to the number of threads in a process
>> ?

> A
>> test program I was writing created approximately 105 threads for a
>> process
>> ( many unused because of some thread pool code ), and an out of memory

> error
>> occurred when an attempt was made to create more threads. Since I do not
>> believe that the application was using much memory compared to the nearly

> 1
>> GIG of total virtual memory, I assume that the out of memory exception
>> had
>> to do with exceeding a thread creation limit for a single process.
>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Number of threads in a process question Arne Vajhøj Microsoft C# .NET 0 22nd Sep 2010 03:15 AM
Re: Number of threads in a process question Rick Lones Microsoft C# .NET 0 21st Sep 2010 01:47 PM
Re: Number of threads in a process question Arne Vajhøj Microsoft C# .NET 0 21st Sep 2010 01:05 AM
Maximum number of threads =?Utf-8?B?QW1pciBTaGl0cml0?= Microsoft Dot NET 4 20th Sep 2006 06:17 AM
Maximum number of process....Windows Vinay Microsoft Windows 2000 File System 1 24th Apr 2004 12:15 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:04 PM.