.net 4.0 - Task Parallel Library. Nested task do not start -
I am working with the new TPL library and I am facing some strange behavior, I understand not can. For some reasons nested work has not started in my case. I have simplified the following solutions:
bool flag = false; For (Int i = 0; I <5+ i ++) {Tasks. Factory STARTNU (() = & gt; {while (true) // lots of new things to come {THREAD.Sleep (200); // SOME WORK WORK. Factory.startu (() => {flag = true} ;});}}); } Thread Sow (2000); Assert.IsTrue (flag);
I have 5 tasks that are running simultaneously, each task gets some elements from the pending queue, do some operations and then try to run nested work for the results of this operation. Please. The problem is that if there are so many elements (whereas the (fact) limits it) and all 5 functions are not continuously nested functions. Loop can only be started after a lot of tasks while completing its execution.
Tasks. Factor Startup does not start a task, it adds to the list of tasks to be determined by the task and determines the scheduler to run the work on the basis of things; The number of available cores (the size of the thread pool), the current CPU load and the current work throughput.
You should read section about task scheduling here:
pdf page 63.
Long lasting option Bypassing the thread pool completely eliminates your problem "fixes" There are some disadvantages in it, this should allow you to create more threads from your system, which should be actually used, due to excessive reference switching, lower performance will be shown.
The threads used are misguided because the threads are "stupid" schedules, it sees that more work has been added and the CPU load has not increased yet. 62 You should change sleep with a tight loop that includes math (such as Sqrt) for example.
A single external loop that reads items from a queue and executes them on the task In this way, your application will use the parallelization of the system without overloading.
The following answer can be of a value:
Comments
Post a Comment