Using System.Threading.Tasks.Parallel create new thread in the thread pool?

前端 未结 4 617
慢半拍i
慢半拍i 2021-02-06 11:45

Maybe I did not understand it right ... all the Parallel class issue :(

But from what I am reading now, I understand that when I use the Parallel I actually mobilize

4条回答
  •  清酒与你
    2021-02-06 12:35

    I think you have this the wrong way round. From PATTERNS OF PARALLEL PROGRAMMING you'll see that Parallel.ForEach is just really syntactic sugar.

    The Parallel.ForEach is largely boiled down to something like this,

    for (int p = 0; p < arrayStrings.Count(); p++)
    {
        ThreadPool.QueueUserWorkItem(DoSomething(arrayStrings[p]);
    }
    

    The ThreadPool takes care of the scheduling. There are some excellent articles around how the ThreadPool's scheduler behaves to some degree if you're interested, but that's nothing to do with TPL.

提交回复
热议问题