Basic multithreaded questions in C #

I am new to multithreading and I am working on parallelizing the area in my application. I read a few posts on this site, but I'm still confused about the best approach to my problem:

[1] In .NET 3.5, is there a ThreadPoolsingle way to use multiple cores in a machine? those. Is it possible to create threads on different cores with new Thread()?

[2] My business: I have List<Calculation>one that contains about 80 items that are currently being processed sequentially. Therefore, given that I am using .NET 3.5 and based on what I read, ThreadPoolit is probably the best option for multithreading due to the large number of threads:

  • There is a big correlation between the calculations. Currently, the list is arranged in such a way that all necessary calculations are performed at the beginning.

Here's what the dependency of work items looks like (details are not important, I just would like to determine the complexity of the dependencies):

alt text

  • The calculation time is very different, one Calculation object can simply include extracting a value, other calculation objects will include a lot of work in nested loops ... etc.

How to determine the priority of the main one Calculations, which will have something like 10 other work items, depending on this? What is the most efficient way to use alarms?

Thank.

: , List<Calculation> . 80+ x . , , Calculate() Calculation .

+3
4

[1] .NET 3.5, ThreadPool - ? .. Thread()?

, , . ( , ).

ThreadPool , Thread, ( )

[2] : Listthat 80 , . , , .NET 3.5 , , ThreadPool, , - :

ThreadPool.QueueWorkItem .

, 100 , 10 , 10 . , 10 , , .net .

  • List Queue
  • 10 ( , ) ThreadPool.QueueWorkerItem(MyMethod);
  • MyMethod , , .
+1

[1]: , new Thread(), , threadpool. :

Thread vs ThreadPool

+2

SO MUCH EASIER .Net 4.0, .

? , .

, Thread.BeginThreadAffinity, , CPU. .

+2

, PLINQ .

List<Calculation> foo = ...;
foo.AsParallel.Select(c => c.Calculate());
0
source

Source: https://habr.com/ru/post/1773103/


All Articles