deleting a thread.

deleting a thread.

Imagen de Venkata Ravi Kumar A.

Hi All,


In my code I have some thing like below

tbb::tbb_thread*     m_tbbTimerThread; m_tbbTimerThread=new tbb::tbb_thread(&sFirstTimerBlocked,this);

// Above thread is spawned.

Later I want to deleted thread in different function. I am doing it as below.

if(m_tbbTimerThread!= NULL){delete m_tbbTimerThread;} m_tbbTimerThread= NULL;

Is this right way of doing. Is thread better way of doing this? Are thread delete API exists?


publicaciones de 2 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.
Imagen de Raf Schietekat

You may delete the thread object only after calling join() or detach(). If you want to delete the O.S. thread, you would typically tell it to stop, e.g., by writing to an atomic<bool> that is regularly checked by the thread and interpreted as a request to return. Forcefully stopping the thread is supported by O.S. calls, but is not recommended for threads running C++ code.

Inicie sesión para dejar un comentario.