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

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -