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

Popular posts from this blog

javascript - How to process users in one specific order using map o each function? -

java - Two interface have same method name with different return type -

javascript - Linking from page A to a specific iframe on page B -