c++ - Determine if code is running in specific thread -
in application run background operation using snippet:
m_thread = std::thread(&myclass::backop, this);
sometimes different threads (including m_thread
itself, possibly) in application call function close()
waits background thread complete operation:
if(m_thread.joinable()) m_thread.join();
and unsafe behaviour, if right, may cause deadlock.
can determine in close()
function text, if running in background thread, skip "joining"?
thank you!
can determine in
close()
function if running in background thread, skip "joining"?
yes, can use std::this_thread::get_id()
function , compare m_thread.get_id()
determine if routine runs within same std::thread
instance.
Comments
Post a Comment