Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.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++ std::线程子体的std::vector_C++_Multithreading_C++11_Vector_Stl - Fatal编程技术网

C++ std::线程子体的std::vector

C++ std::线程子体的std::vector,c++,multithreading,c++11,vector,stl,C++,Multithreading,C++11,Vector,Stl,我试图创建一个线程向量,其属性是销毁时自动连接。Stroustrup建议使用防护螺纹: struct guarded_thread : std::thread { using std::thread::thread; ~guarded_thread() { if (joinable()) join(); } }; 此保护线的工作原理类似于魅力: void f() { std::cerr << "f();" << std::endl; } int main

我试图创建一个线程向量,其属性是销毁时自动连接。Stroustrup建议使用防护螺纹:

struct guarded_thread : std::thread {
    using std::thread::thread;
    ~guarded_thread() { if (joinable()) join(); }
};
此保护线的工作原理类似于魅力:

void f() { std::cerr << "f();" << std::endl; }
int main() { guarded_thread gt(f); }

void f(){std::cerr似乎
guarded_thread
缺少默认的移动构造函数,应该删除复制构造函数

这是一个有效的例子

guarded_thread(const guarded_thread&) = delete ;
guarded_thread(guarded_thread&&) = default ;

注意:您的代码正在调用一个已删除的函数,即
std::thread
copy构造函数,并且也没有提供移动构造函数。

copy构造函数已在基(线程)中删除。请求默认移动构造函数解决了问题,谢谢!
template<typename _Callable, typename... _Args>
  explicit
  thread(_Callable&& __f, _Args&&... __args)
  {
  #ifdef GTHR_ACTIVE_PROXY
    __asm ("" : : "r" (&pthread_create));
  #endif
    _M_start_thread(_M_make_routine(std::__bind_simple(
            std::forward<_Callable>(__f),
            std::forward<_Args>(__args)...)));
  }
guarded_thread(const guarded_thread&) = delete ;
guarded_thread(guarded_thread&&) = default ;