In a .Net process, there is only one managed thread pool. We can set the minimum and maximum thread count as needed via public properties.
In .Net, we also have Parallel.ForEach
that gets its threads from this managed thread pool under the hood.
In Parallel.ForEach
we can also set the MaxDegreeOfParallelism
to limit the maximum number of threads.
I have two Parallel.ForEach
running in parrallel. One has MaxDegreeOfParallelism
set to 3 and the other has set to 7.
My question is: Does both my Parallel.ForEach
loops use the same thread pool under the hood. If yes, how does Parallel.ForEach
limits the threads with MaxDegreeOfParallelism
. How multiple
Parallel.ForEach
loops and one managed thread pool work together?
It'll really help if you can provide a high level explanation or some pointers before I peak into the .net core source code.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…