0

I'm using a Merge class to encapsulate a merge sort. I'd like to use a packaged task to multithread the recursive calls:

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();
}

I was just wondering if I could bind packaged task like this:

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();
}
Lucretiel
  • 3,145
  • 1
  • 24
  • 52
  • What happened when you tried? – John Zwinck Mar 26 '12 at 16:12
  • It's not clear what exactly you are trying to do. I would expect a function that takes two arguments to sort a range, yet executeSort takes no arguments. when calling bind you need to identify the function, the object and the parameters. – Guy Sirton Mar 26 '12 at 18:31
  • There's no multithreading in this code, invoking a `packaged_task` does not run in a separate thread. – Jonathan Wakely Apr 21 '13 at 20:21

0 Answers0