我正在努力使快速排序并行,线程是第一次尝试。非线程版本正确排序,但线程不正确(这并不奇怪)。我发现有趣的是,当我删除线程但保留 boost::bind 调用时它仍然不起作用。如果 boost::bind 不是我想要的,请提出建议。Bind 似乎是使我的函数与 boost 线程一起工作的最简单(或唯一)的方法。
void Quicksort( fVec &Array, const int Left, const int Right )
{
if( Right <= Left )
return;
int pivot = Left;
const int pivotNewIndex = Partition( Array, Left, Right, pivot );
// These function calls make it work fine
//Quicksort( Array, Left, pivotNewIndex - 1 );
//Quicksort( Array, pivotNewIndex + 1, Right );
// boost::bind calls only swaps one element, doesn't actually sort
boost::bind( &Quicksort, Array, Left, pivotNewIndex - 1 )();
boost::bind( &Quicksort, Array, pivotNewIndex + 1, Right )();
// threaded version that doesn't work, same as above
//boost::thread threadA( boost::bind( &Quicksort, Array, Left, pivotNewIndex - 1 ) );
//threadA.join();
//boost::thread threadB( boost::bind( &Quicksort, Array, pivotNewIndex + 1, Right ) );
//threadB.join();
}