deleting a thread.

deleting a thread.

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?


2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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.

Leave a Comment

Please sign in to add a comment. Not a member? Join today