Using concurrency runtime for non computational code RRS feed

  • Question

  • Hi all!

    Yesterday i learned about concurrency runtime. It's very nice and powerfull thing. :)

    I decide to implement one ot my recent tasks from Win32 threads to this runtime (for educational purposes). Here the description on my task:

    1. Client obtain from Active Directory list of our servers.

    2. For each server client obtain list of IP addresses.

    3. For each server client try to do the following tests (this part i want to reimplement):

      1. Ping each address of server

      2. Test connection to server via RPC.

    4. All results (test connection and ping) are displayed to the network administrator.

    I implement step 3 like this:

    parallel_for_each(_Servers.begin(), _Servers.end(), [this](const CServerInfo& Info) {

    method BeginTests implementhed like this:

    void BeginTests(const CServerInfo &Info)
     // _Tasks has "task_group" type[this, Info] {
[this, Info] {


    This code works but it creates one thread for one CPU core. As result i see what not all tasks execute in parallel. In my Win32 Threads raw implementation i create 2*N thread (N - number of servers, for example, 10) and it works much faster when implementation with concurrency runtime.

    How to reach similar behaviour with concurrency runtime?


    Wednesday, April 6, 2011 12:10 PM


  • If you want to have more control over the number of threads created in the Scheduler you can can construct a Scheduler explicitly with a 'SchedulerPolicy' to do this, e.g. via the code below; a more thorough example is also at:

    To create the default scheduler with a specific number of threads you can do the following:

    int numThreads = GetProcessorCount() * 2;   //GetProcessorCount is defined in concrtrm.h


    Rick Molloy Parallel Computing Platform :
    Thursday, April 7, 2011 9:01 PM