0

我正在使用 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();
}
4

0 回答 0