Max. Thread Amount of Windows XP and / or Windows Server 2003

  • Thread starter Thread starter schuetz
  • Start date Start date
S

schuetz

Hi @ll,

I'm working on a web project which has to use multiple channels to
connect to receive several sources at once. The problem is, that I'm
not aware of the maximum amount of Threads i can allocate to my
channels.

Can i open 10 threads, 100 threads even 1000?

is there a general answer to it. my dev. environment runs on win. xp
and the application will run on a ms server 2003.

Kind regards,
Roni Schuetz
 
While you can open as many as you like, each thread taxes system resources
moderately. .NET makes the threadpool class available to help perform thread
related tasks without having to manage creation and destruction of threads.

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
 
It is around 2000, but is a function of memory and stack size.
http://blogs.msdn.com/oldnewthing/archive/2005/07/29/444912.aspx

--
William Stacey [MVP]

| Hi @ll,
|
| I'm working on a web project which has to use multiple channels to
| connect to receive several sources at once. The problem is, that I'm
| not aware of the maximum amount of Threads i can allocate to my
| channels.
|
| Can i open 10 threads, 100 threads even 1000?
|
| is there a general answer to it. my dev. environment runs on win. xp
| and the application will run on a ms server 2003.
|
| Kind regards,
| Roni Schuetz
|
 
It is a function of stack size, but you can change the stack size by calling
the CreateThread API directly (not sure if its in your link or not)
 
So this is really interesting to me. I completely agree with the analysis
but for curiosity sake, I wrote a small app to test the theory. My code
follows. With the catch block commented out, studio 05 explodes with a bang
indicating some sort of package error and then disappears from screen.
Subsequent runs do not even provide an error message, visual studio 2005 on
XP simple disappears. Can anyone reproduce this?

As an aside, without the .start() call, the application will actually run to
completion. I'm not entirely sure what's happening there. Under the
debugger, I can only see 4 threads so it seems the threads aren't *actually
being created, it appears that they are created when start() is called - at
least that's my initial analysis. With the catch block i was able to create
and run 1401 threads. I'll accept that as close enough.

using System;

using System.Collections.Generic;

using System.Text;

using System.Threading;

namespace ConsoleApplication1

{

public class Threaded

{

public void DoWork()

{

System.Threading.Thread.Sleep(-1);

return;

}

}

class Program

{

static void Main(string[] args)

{

Threaded mythread = new Threaded();

int i = 0;

Thread var = null;

//try

{

for (; i < 1000000; i++)

{

var = new Thread(new ThreadStart(mythread.DoWork));

if (var == null)

{

break;

}

var.Name = i.ToString();

var.Start();

}

}

//catch

{

}

Console.Write(i.ToString());

System.Threading.Thread.Sleep(1500);

}

}

}


--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
 
"Alvin Bruney" <www.lulu.com/owc> wrote in message
| So this is really interesting to me. I completely agree with the analysis
| but for curiosity sake, I wrote a small app to test the theory. My code
| follows. With the catch block commented out, studio 05 explodes with a
bang
| indicating some sort of package error and then disappears from screen.
| Subsequent runs do not even provide an error message, visual studio 2005
on
| XP simple disappears. Can anyone reproduce this?
|

No, I don't. I can create 1948 threads when run in VS2005, at that point the
CLR throws an OOM exception.
Guess you are exhausting your available Virtual Memory space (pageable RAM +
free page file space), before you reach the maximum Virtual Address Space
for a Win32 process (~2GB).
You can increase the page file size and try again.


| As an aside, without the .start() call, the application will actually run
to
| completion. I'm not entirely sure what's happening there. Under the
| debugger, I can only see 4 threads so it seems the threads aren't
*actually
| being created, it appears that they are created when start() is called -
at
| least that's my initial analysis. With the catch block i was able to
create
| and run 1401 threads. I'll accept that as close enough.
|

The OS thread is created when Start() is called, don't know why you see 4
threads in the debugger, you should only have 3 threads before you start the
first auxiliary thread.



Willy.
 
This definitely seems to be a bug in studio. I could reproduce this
everytime with the catch block commented out.
Guess you are exhausting your available Virtual Memory space (pageable RAM
+
free page file space), before you reach the maximum Virtual Address Space
I don't think so. I did play with the page file a bit but the best I could
get on my dell laptop was 1843 with page file set to 2 meg.

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
 
"Alvin Bruney" <www.lulu.com/owc> wrote in message
| This definitely seems to be a bug in studio. I could reproduce this
| everytime with the catch block commented out.
|

Well, I can't, running VS2005 Team System.

| > Guess you are exhausting your available Virtual Memory space (pageable
RAM
| > +
| > free page file space), before you reach the maximum Virtual Address
Space
| I don't think so. I did play with the page file a bit but the best I could
| get on my dell laptop was 1843 with page file set to 2 meg.

Hmm... 2MB, must be your problem :-)
How much RAM do you have available? What else do you have running?

The code you posted both, Debug and release version:
Stop with console message:
Unhandled Exception: OutOfMemoryException.

after 1949 threads created and a VM size 2.005.132K

1949 threads, that is 3 initial threads + 1946 auxiliary.

Run debug mode (CTRL F5) debug version:

stop at var.Start() with unhandle exception dialog (debugger)
Exception of type 'System.OutOfMemoryException' was thrown.

after 1889 threads created and VM 1.954.748K

Note that in all cases Commited memory > 2.3GB on an empty system (not
running anyhing else then VS).

Willy.
 
I'm running 512megs.
Console exception:
Commit Charge
T 2542844
L 2566648
P 2561452

Everything works similar to what you reported except when I run straight F5.
The exception on screen is Package Load Failure GUID =
{8D8529D3-625D-4496-8354-3DAD630ECC1B} prompt follows to disable devenv
/resetskippkgs
Sometimes this is followed by the OOM error, other times its the VS studio
crapping out. I'm not running Team System.

Digging a little deeper, it seems this problem was around before and may
have been caused by earlier versions. See
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=126741&SiteID=1.
However, this is a new laptop and the only version of studio is VS 2005.
I've run a tool built by MS to detect and fix that type of error, however
the tool found nothing wrong. I guess this is a nasty issue. why me why me
--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
 
Package Unload Error Troubleshooter Guide (searchable title)

For those of you running into package unload problems Microsoft (Aaron
Stebner) recommends using this definitive package unload trouble-shooter
guide to resolve the issue.

http://blogs.msdn.com/astebner/archive/2005/12/16/504906.aspx

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------

Alvin Bruney said:
I'm running 512megs.
Console exception:
Commit Charge
T 2542844
L 2566648
P 2561452

Everything works similar to what you reported except when I run straight
F5. The exception on screen is Package Load Failure GUID =
{8D8529D3-625D-4496-8354-3DAD630ECC1B} prompt follows to disable devenv
/resetskippkgs
Sometimes this is followed by the OOM error, other times its the VS studio
crapping out. I'm not running Team System.

Digging a little deeper, it seems this problem was around before and may
have been caused by earlier versions. See
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=126741&SiteID=1.
However, this is a new laptop and the only version of studio is VS 2005.
I've run a tool built by MS to detect and fix that type of error, however
the tool found nothing wrong. I guess this is a nasty issue. why me why
me
--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Professional VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------

Willy Denoyette said:
"Alvin Bruney" <www.lulu.com/owc> wrote in message
| This definitely seems to be a bug in studio. I could reproduce this
| everytime with the catch block commented out.
|

Well, I can't, running VS2005 Team System.

| > Guess you are exhausting your available Virtual Memory space
(pageable
RAM
| > +
| > free page file space), before you reach the maximum Virtual Address
Space
| I don't think so. I did play with the page file a bit but the best I
could
| get on my dell laptop was 1843 with page file set to 2 meg.

Hmm... 2MB, must be your problem :-)
How much RAM do you have available? What else do you have running?

The code you posted both, Debug and release version:
Stop with console message:
Unhandled Exception: OutOfMemoryException.

after 1949 threads created and a VM size 2.005.132K

1949 threads, that is 3 initial threads + 1946 auxiliary.

Run debug mode (CTRL F5) debug version:

stop at var.Start() with unhandle exception dialog (debugger)
Exception of type 'System.OutOfMemoryException' was thrown.

after 1889 threads created and VM 1.954.748K

Note that in all cases Commited memory > 2.3GB on an empty system (not
running anyhing else then VS).

Willy.
 

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

Back
Top