unstructured task_group sample

Example using unstructured task_group (recursive fibonacci computation). It’s pretty useless but this shows at least dynamic addition of tasks into the task_group.

#include "stdafx.h"
#include <ppl.h>
 
using namespace Concurrency;
 
void task_fibo(task_group& tasks, combinable<unsigned int>& comb, unsigned int n)
{
    if( 1 >= n )
    {
        comb.local() += n;
    }
    else
    {
        tasks.run([&, n] { task_fibo(tasks, comb, n-1); });
        tasks.run([&, n] { task_fibo(tasks, comb, n-2); });
    }
}
 
void task_fibo()
{
    unsigned int n = 30;
 
    task_group tasks;
    combinable<unsigned int> comb;
    tasks.run_and_wait([&] { task_fibo(tasks, comb, n); });
    unsigned int fibo_n = comb.combine( std::plus<unsigned int>() );
    std::cout << "Fibo(" << n << ") = " << fibo_n << std::endl;
}