locked
Async operations are backed by threadpool?

    Question

  • I want to know some internals of async operations in metro app. For example, by calling a metro API like CreateFolderAsync, what happens to the async task thus created? Does windows create a separate thread for this task and most importantly, Are these threads assigned to some threadpool?

    If the threads do not belong to a thread pool, then who controls the degree of parallelism at any point? Is it a job of programmer to throttle the number of asynchronous tasks at any time or it is all done internally?

    Is there some reference on MSDN which I can read to know these internal details? All references just point to the async programming practices.

    Wednesday, September 12, 2012 9:11 AM

Answers

  • Hi John,

    Generally when you start a new parallel Task / async operation , this will be most likely scheduled on the managed threadpool. The threadpool may end up creating a new thread or it may end up re-using one. Totally depends on the load upon the threadpool.

    I hope that helps.

    -Sagar


    • Marked as answer by John Rick Tuesday, September 18, 2012 8:47 AM
    Monday, September 17, 2012 2:10 PM
    Moderator

All replies

  • Metro(WinRT) APIs are completely asynchronous. If any operation takes more than couple of milliseconds it runs in background and current execution is continued.

    CreateFolderAsync takes some times, so it runs asynchronously in background automatically and current execution will never wait for it result rather it is continued for executing the subsequent instructions. Actually asynchronous operation does not returns result immediately rather it returns the way of result. It is controlled internally and application always keep responsive.

    • Proposed as answer by Mokarrom Hossain Thursday, September 13, 2012 2:42 PM
    • Unproposed as answer by John Rick Saturday, September 15, 2012 1:19 PM
    Wednesday, September 12, 2012 6:00 PM
  • I know very well these are asynchronous operations and that much detail. I wanted to know that who manages the degree of parallelism in system? i.e. if I create 1000 async tasks, will the OS manage to schedule them properly by not overloading the system? or as a programmer I have to make a note of this load?
    Saturday, September 15, 2012 1:21 PM
  • Hi John,

    Generally when you start a new parallel Task / async operation , this will be most likely scheduled on the managed threadpool. The threadpool may end up creating a new thread or it may end up re-using one. Totally depends on the load upon the threadpool.

    I hope that helps.

    -Sagar


    • Marked as answer by John Rick Tuesday, September 18, 2012 8:47 AM
    Monday, September 17, 2012 2:10 PM
    Moderator
  • The recommendation for C++ developers is to use the task library from the Parallel Patterns Library. The task class and related constructs simplify all aspects of async programming for C++ developers. PPL itself is built on top of the native concurrency runtime (also called ConcRT). 

    In short, yes you need not worry about having to manage the degree of parallelism. ConcRT is very well designed to take care of all these details for you.

    Hope this helps.

    Monday, September 17, 2012 4:41 PM