How many threads possible?

G

GroupReader

Each .net app, by default, has 25 threads (per processor) in the
threadpool, right? ... but when calling ThreadStart, I'm creating a
new thread and not using the threadpool, right?

I don't want to get into any lengthy discussion about the
best-practices and the best use of threads etc... I'm asking this
question just to satisfy my own curiosity:

On a typical windows server computer (Win2000 server or Win2003
server), how many threads can one create (using ThreadStart) before
running out of threads? What does it depend on? The number of
processors? Amt of RAM? The operating system? Machine.config
variables?

What's a ballpark figure on how many threads would be a typical upper
limit? Is the number in the hundreds or thousands or tens of
thousands?

Any feedback would be appreciated.

Thanks.
 
P

Patrice

If I remember I saw once an article saying this is mostly memory bound (that
is there is no hardcoded limit, it is just limited by the resource that is
exhausted first that is likely memory). You could also just give this a try
on your own machine to establish a lower limit.

As you noted this is anyway a theorical limit...
 
B

Bob Milton

By default, each OS thread gets 1 Meg of address space for its stack.
For normal windows, any process is limited to 2 Gig of address space for the
program. Thus, the ultimate limit is 2048 threads if your code takes no
space (highly unlikely).
Bob
 
G

GroupReader

Thanks for the quick answers!

I also ran a quick test as suggested which seems to support the 2048
limit. I created a loop that spawns new threads and got an "out of
memory exception" at just above 1800 threads.

For the record if anyone cares, my test was run on WinXP Pro, with 1GB
RAM total (about 250MB free), and only about 1.5GB of free disk space.

Thanks again.
 

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