mercredi 22 juillet 2015

Determine if code is running in specific thread

In C++ i run background operation using this snippet:

m_thread = std::thread(&MyClass::BackOp, this);

Sometimes different threads (including m_thread itself) in my application execute method Close() which runs this code to wait for background thread to complete its operation:

if(m_thread.joinable()) m_thread.join();

And this is unsafe behaviour, if i am right.

Can i determine in my Close() function if it is running in my background thread, to skip "joining"?

Thank you!

Aucun commentaire:

Enregistrer un commentaire