2010-12-29 12 views
5

alguien puede por favor decirme podemos reenviar declarar un boost :: thread variable. boost :: thread t (hilo); inicia un hilo, pero quiero declararlo en alguna parte y comenzarlo en otro lado. Gracias por adelantado.forward declaration of boost :: thread variable

Cuando uso

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 

Respuesta

4

Que yo sepa, la única manera de hacerlo es utilizar thread 's 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`. 

EDIT: A partir de los mensajes de error que posteaste, parece que no puedes usar la semántica de movimientos con tu versión de boost. Si ese es el caso, me temo que no podrá inicializar una instancia de thread y que comience más tarde.

+0

¿qué quieres decir con tu invocable? cómo es diferente de su_función (como escribió antes de editar) – Shweta

+0

@Shweta, un invocable también puede ser una instancia de una clase cuyo 'operador()' se ha sobrecargado (a veces llamado un [objeto de función]) (http: // en .wikipedia.org/wiki/Function_object # In_C_and_C.2B.2B)). Hice ese cambio para completar :) –

+0

lo siento no funciona – Shweta

Cuestiones relacionadas