【发布时间】:2014-06-11 16:40:16
【问题描述】:
我正在尝试将向量发送到另一个线程函数的参数:
void foo(){}
const int n = 24;
void Thread_Joiner(std::vector<thread>& t,int threadNumber)
{
//some code
}
int main()
{
std::vector<thread> threads(n, thread(foo));
thread Control_thread1(Thread_Joiner, threads, 0);//error
thread Control_thread2(Thread_Joiner, threads, 1);//error
//...
}
上面的代码给出了这个错误:
: attempting to reference a deleted function
我检查了std::thread的头文件似乎删除了复制构造函数:thread(const thread&) = delete;
std::thread 有一个移动构造函数,但我认为在这种情况下使用移动没有帮助,因为Control_thread1 和Control_thread2 使用相同的vector!
如果我使用 thread **threads;... 而不是 vector 它可以正常工作,但我不想使用 pointers 。
我该怎么办?!
【问题讨论】:
标签: c++ multithreading c++11 stl stdthread