我正在使用Merge类来封装合并排序。我想使用打包的任务多线程递归调用:
void Merge::executeSort()
{
packaged_task<void(Merge)> mergeLeft(bind(Merge::executeSort, _1));
packaged_task<void(Merge)> mergeRight(bind(Merge::executeSort, _1));
auto f1 = mergeLeft.get_future();
auto f2 = mergeRight.get_future();
mergeLeft(Merge(arrayBegin, arrayMiddle()));
mergeRight(Merge(arrayMiddle(), arrayEnd));
f1.get();
f2.get();
merge();
}
我只是想知道我是否可以绑定这样的打包任务:
void Merge::executeSort()
{
packaged_task<void(int*, int*)> mergeLeft(bind(Merge::executeSort, Merge(_1, _2)));
packaged_task<void(int*, int*)> mergeRight(bind(Merge::executeSort, Merge(_1, _2)));
auto f1 = mergeLeft.get_future();
auto f2 = mergeRight.get_future();
mergeLeft(arrayBegin, arrayMiddle());
mergeRight(arrayMiddle(), arrayEnd);
f1.get();
g2.get();
merge();
}