Visual C++本地并行编程中的状态管理

2020-01-06 12:36:01王旭

  //add an element to the vector using three separate tasks

  parallel_invoke(   [&]{ v.local().push_back(1); },

  [&]{ v.local().push_back(2); },

  [&]{ v.local().push_back(3); }

  );

  //merge the task-local copies using combine_each

  vector< int> result1;

  v.combine_each(

  [&](vector< int>& local)

  {

  result1.insert(result1.end(),

  local.begin(), local.end());

  }

  );

  //merge the task-local copies using combine

  vector< int> result2 = v.combine(

  [](vector< int> left, vector< int> right)->vector< int>{