3

What is the maximum number of thread in an application 32-bits and 64-bits developed in Delphi?

I need to know what is the limit of threads running simultaneously on a 32-bit application, because I'm doing performance analysis and I want to let the OS manage the execution order of the threads that are waiting.

Gonze
  • 31
  • 3
  • Notice that - generally speaking - if you create more threads than processor cores (or virtual equivalents), you will not gain any performance advantage. If you create too many, you'll even end up with pretty bad results like these: http://thedailywtf.com/Articles/Less-is-More.aspx So are you completely sure that you'll need the theoretically possible maximum number of threads? – Hauke P. Jun 06 '13 at 23:12
  • 1
    The OS always manages thread execution...that's its job. http://blogs.msdn.com/b/oldnewthing/archive/2007/03/01/1775759.aspx – J... Jun 06 '13 at 23:14
  • For the record though, you can probably support 4294967295 threads on a 32 bit machine, and 18446744073709551615 on a 64 bit machine before you literally can't keep track of them any more. – Chris Jun 06 '13 at 23:15
  • 3
    @Chris - I think that's absolute nonsense. Consider that each thread needs its own stack space and, at a default of 1MB per thread, you run out of user space with about 2000 threads in 32-bit. You can tune the stack space down a bit, but you're never going to get four billion - ever. – J... Jun 06 '13 at 23:18
  • 4
    @J... It was a joke about MAX_INT.... A bad one admittedly. My point is that the number of threads that *can theoretically be run* is an entirely different question from the number that is *practical for your application*. – Chris Jun 06 '13 at 23:20
  • You should have a look at http://www.deltics.co.nz/blog/?p=1297 and don't miss part 2 to get your answer - because it depends on your application/threads needs – Sir Rufo Jun 06 '13 at 23:34
  • It seems to me this question is Delphi-specific so it is still worth contributing. One piece of advice that has served me well over the years : From the Delphi6 developer's guide (9-11) `The recommended limit is 16 threads per process on single processor systems. This limit assumes that most of those threads are waiting for external events. If all threads are active, you will want to use fewer.` This rule of thumb concurs with the cited answer `hundreds is probable on current server and desktop hardware but risky`. – Hugh Jones Jun 07 '13 at 09:00
  • @Chris sorry... it's so hard to tell around here sometimes ;) – J... Jun 07 '13 at 11:28

1 Answers1

0

You might want to read this answer: https://stackoverflow.com/a/481919/1560865

Still, what I wrote in my comment above stays partially true (but please also notice Martin James' objection to it below).

Notice that - generally speaking - if you create way more threads than processor cores (or virtual equivalents), you will not gain any performance advantage. If you create too many, you'll even end up with pretty bad results like these: thedailywtf.com/Articles/Less-is-More.aspx So are you completely sure that you'll need the theoretically possible maximum number of threads?

Community
  • 1
  • 1
Hauke P.
  • 2,695
  • 1
  • 20
  • 43
  • 2
    Yes, but that comment is stup.. incomplete. The box on which I write this has 4/8 cores and 1260 threads created. It works fine. Sorry, but the claim in your comment is grossly misleading at best. If the threads make blocking calls, eg. network stuff like DNS lookups, there will be a massive performance boost from using many more threads than cores. The only reason I don't downvote this is that you would be singled out amongst all the other purveyors of thread-FUD. That said, I agree that any design that requires thousands of threads should be.. 'examined carefully'. – Martin James Jun 06 '13 at 23:39
  • Aw, its already pretty late here already. You're completely right. – Hauke P. Jun 06 '13 at 23:48
  • This was perfect as a comment, but it does nothing to answer the question asked. It ends up asking for confirmation instead: "So are you completely sure...?" Answers should actually include an answer to the question. I'm not downvoting, but others might not be so kind. :-) – Ken White Jun 07 '13 at 02:06
  • :-( I linked to another non-answering answer to a similar question which got upvoted quite a bit and was even made the accepted answer after all. So is the additional information in my comment actually *that* bad? – Hauke P. Jun 07 '13 at 08:35
  • StackOverflow has the option to close as duplicate, which is already done. – Jerry Dodge Jun 07 '13 at 15:51