Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/145.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;11在没有活动异常的情况下调用快速排序终止_C++_Multithreading_C++11_Concurrency - Fatal编程技术网

C++ C++;11在没有活动异常的情况下调用快速排序终止

C++ C++;11在没有活动异常的情况下调用快速排序终止,c++,multithreading,c++11,concurrency,C++,Multithreading,C++11,Concurrency,我输入了《C++并发操作》一书中的以下示例,但它报告: "terminate called without an active exception". 看起来问题出在spawn_任务的功能上,但我不知道会出什么问题 template<typename F, typename A> static std::future<typename std::result_of<F(A&&)>::type> spawn_task(F&&

我输入了《C++并发操作》一书中的以下示例,但它报告:

"terminate called without an active exception". 
看起来问题出在spawn_任务的功能上,但我不知道会出什么问题

template<typename F, typename A>
static std::future<typename std::result_of<F(A&&)>::type> spawn_task(F&& f, A&& a)
{
    typedef typename std::result_of<F(A&&)>::type result_type;
    std::packaged_task<result_type(A&&)> task(std::move(f));
    std::future<result_type> res(task.get_future());
    std::thread(std::move(task), std::move(a));
    return res;
}
template<typename T>
static std::list<T> parallel_quick_sort(std::list<T> input)
{
    if (input.empty())
    {
        return input;
    }

    std::list<T> result;
    result.splice(result.begin(), input, input.begin());
    T const& partition_val = *result.begin();
    typename std::list<T>::iterator divide_point = std::partition(
            input.begin(), input.end(), [&](T const& t)
            {   return t<partition_val;});
    std::list<T> lower_part;
    lower_part.splice(lower_part.end(), input, input.begin(), divide_point);


    std::future<std::list<T> > new_lower(
            spawn_task(&parallel_quick_sort<T>, std::move(lower_part)));

    std::list<T> new_higher(parallel_quick_sort(std::move(input)));
    result.splice(result.end(), new_higher);
    result.splice(result.begin(), new_lower.get());
    return result;

}



static void test()
{
    std::list<int> toSort={1,4,3,6,4,89,3};
    std::for_each(std::begin(toSort), std::end(toSort), [](int n){ std::cout << n << std::endl;});
    std::list<int> sorted;
    sorted=parallel_quick_sort(toSort);
    std::for_each(std::begin(sorted), std::end(sorted), [](int n){ std::cout << n << std::endl;});
}
模板
静态std::未来生成任务(F&&F,A&&A)
{
typedef typename std::result_of::type result_type;
std::packaged_任务(std::move(f));
std::future res(task.get_future());
std::线程(std::移动(任务),std::移动(a));
返回res;
}
模板
静态std::列表并行\快速\排序(std::列表输入)
{
if(input.empty())
{
返回输入;
}
std::列表结果;
拼接(result.begin(),input,input.begin());
T const&partition_val=*result.begin();
typename std::list::迭代器divide\u point=std::partition(
input.begin()、input.end()、[&](T const&T)

{return tErr..我在谷歌上做了一些研究后发现了这一点

我修复了如下代码:

template<typename F, typename A>
static std::future<typename std::result_of<F(A&&)>::type> spawn_task(F&& f, A&& a)
{
    typedef typename std::result_of<F(A&&)>::type result_type;
    std::packaged_task<result_type(A&&)> task(std::move(f));
    std::future<result_type> res(task.get_future());
    std::thread myThread(std::move(task), std::move(a));
    myThread.detach();
    return res;
}
模板
静态std::未来生成任务(F&&F,A&&A)
{
typedef typename std::result_of::type result_type;
std::packaged_任务(std::move(f));
std::future res(task.get_future());
std::thread(std::move(task),std::move(a));
myThread.detach();
返回res;
}
错误消息指出我有未加入的线程。因此我应该加入或分离。因此我按照上面的方法进行了操作