回答済み When does concurrency scheduler retire threads ?

  • venerdì 8 giugno 2012 14:52
     
     

    I successfully use ppl constructs: agents and task_group in VS10.

    i have a question though. If at some point on my 8 way machine PPL created 8 threads for processing at peek time, after that (hours later) I still see those treads "waiting" - doing nothing. I know that because my process reacts to external events and does nothing but waiting in this case.

    Is it normal to see hours later my process keeping those threads (plus the threads for management from ppl, 11-12 total on my machine) even if it's not having any context switches(process explorer reports indeed one additional context switch increase every few seconds or so)?


    • Modificato raiderG venerdì 8 giugno 2012 14:53
    •  

Tutte le risposte

  • venerdì 8 giugno 2012 18:00
     
     Con risposta

    The concurrency runtime caches threads for later re-use. They are released only when all the concurrency runtime schedulers have been shutdown. (Typically, there is just a single default scheduler in the process). A scheduler is shutdown when all the external threads that queued work to it has exited. So if the main thread scheduled work (by calling parallel_for from main() say) then the default scheduler would be deleted only on process shutdown.

    There is an upper limit on the number of cached threads. It is rougly 4 times the number of cores on the machine (though there are some other factors affecting the threshold like the stack size option in scheduler policies).

    --Krishnan (Microsoft)

    • Contrassegnato come risposta raiderG venerdì 8 giugno 2012 18:53
    •  
  • venerdì 8 giugno 2012 18:53
     
     
    thanks for replay. i indeed understand the need for caching but it seemsstrange for an application that does nothing to keep 14 threads or so sleeping. i really can't tell what would be the best approach in this case though...