有没有人能告诉我,我们能不能向前声明一个boost::thread变量。thread t(thread);启动一个线程,但是我想在某个地方声明它,并在其他地方启动它。提前谢谢。
当我使用
boost::thread t;
t=boost::thread (thread);
/usr/include/boost/noncopyable.hpp: In copy constructor ‘boost::thread::thread(const boost::thread&)’:
/usr/include/boost/noncopyable.hpp:27: error: ‘boost::noncopyable_::noncopyable::noncopyable(const boost::noncopyable_::noncopyable&)’ is private
/usr/include/boost/thread/thread.hpp:35: error: within this context
thr.cpp: In function ‘int main()’:
thr.cpp:20: note: synthesized method ‘boost::thread::thread(const boost::thread&)’ first required here
/usr/include/boost/noncopyable.hpp: In member function ‘boost::thread& boost::thread::operator=(const boost::thread&)’:
/usr/include/boost/noncopyable.hpp:28: error: ‘const boost::noncopyable_::noncopyable& boost::noncopyable_::noncopyable::operator=(const boost::noncopyable_::noncopyable&)’ is private
/usr/include/boost/thread/thread.hpp:35: error: within this context
thr.cpp: In function ‘int main()’:
thr.cpp:20: note: synthesized method ‘boost::thread& boost::thread::operator=(const boost::thread&)’ first required here 发布于 2010-12-29 19:26:41
据我所知,唯一的方法就是使用thread的move semantics
boost::thread t; // Will be initialized to `Not-a-Thread`.
// Later...
t = boost::thread(your_callable);
// Now `your_callable()` runs inside a new thread that has been moved to `t`.编辑:从你发布的错误消息来看,似乎你不能在你的boost版本中使用移动语义。如果是这种情况,我担心您将无法初始化thread实例并在稍后启动它。
https://stackoverflow.com/questions/4553520
复制相似问题