Error running concurrent process and storing results in array

Mathias LANG geod24 at gmail.com
Wed May 6 04:04:14 UTC 2020


On Wednesday, 6 May 2020 at 03:41:11 UTC, data pulverizer wrote:
>
> Is there something I need to do to wait for each thread to 
> finish computation?

Yeah, you need to synchronize so that your main thread wait on 
all the other threads to finish.
Look up `Thread.join`.

> Yes, that's exactly what I want the actual computation I'm 
> running is much more expensive and much larger. It shouldn't 
> matter if I have like 100_000_000 threads should it? The 
> threads should just be queued until the cpu works on it?

It does matter quite a bit. Each thread has its own resources 
allocated to it, and some part of the language will need to 
interact with *all* threads, e.g. the GC.
In general, if you want to parallelize something, you should aim 
to have as many threads as you have cores. Having 100M threads 
will mean you have to do a lot of context switches. You might 
want to look up the difference between tasks and threads.


More information about the Digitalmars-d-learn mailing list