Threadpools, difference between DMD and LDC

Dicebot via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Aug 4 06:36:00 PDT 2014


On Monday, 4 August 2014 at 05:14:22 UTC, Philippe Sigaud via 
Digitalmars-d-learn wrote:
> I have another question: it seems I can spawn hundreds of 
> threads
> (Heck, even 10_000 is accepted), even when I have 4-8 cores. Is 
> there:
> is there a limit to the number of threads? I tried a threadpool
> because in my application I feared having to spawn ~100-200 
> threads
> but if that's not the case, I can drastically simplify my code.
> Is spawning a thread a slow operation in general?

Most likely those threads either do nothing or are short living 
so you don't get actually 10 000 threads running simultaneously. 
In general you should expect your operating system to start 
stalling at few thousands of concurrent threads competing for 
context switches and system resources. Creating new thread is 
rather costly operation though you may not spot it in synthetic 
snippets, only under actual load.

Modern default approach is to have amount of "worker" threads 
identical or close to amount of CPU cores and handle internal 
scheduling manually via fibers or some similar solution.

If you are totally new to the topic of concurrent services, 
getting familiar with http://en.wikipedia.org/wiki/C10k_problem 
may be useful :)


More information about the Digitalmars-d-learn mailing list