Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

deleting a thread.

Venkata_Ravi_Kumar_A
348 Views

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?

Thanks!

0 Kudos
1 Reply
RafSchietekat
Valued Contributor III
348 Views

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.

0 Kudos
Reply