none
When does concurrency scheduler retire threads ?

    Question

  • 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)?


    • Edited by raiderG Friday, June 08, 2012 2:53 PM
    Friday, June 08, 2012 2:52 PM

Answers

  • 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)

    • Marked as answer by raiderG Friday, June 08, 2012 6:53 PM
    Friday, June 08, 2012 6:00 PM

All replies

  • 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)

    • Marked as answer by raiderG Friday, June 08, 2012 6:53 PM
    Friday, June 08, 2012 6:00 PM
  • 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...
    Friday, June 08, 2012 6:53 PM