It seems there is some type of race condition involved. It both works, fails, and hangs regardless of BOOST_THREAD_HAS_EINTR_BUG defined. Weird cuz I never saw anything of the sort in weeks of testing under Windows, and a couple days of testing under MacOS - both using boost synchronization objects.
When it aborts the return is EBUSY.
I am going to change it to use STL just as a data point. The condition variable/mutex pattern here:
~CShareMgr()
{
{
boost::lock_guard< boost::mutex > lock( m_cvMutex );
m_fRunning = false;
}
m_cv.notify_one();
if ( m_thread.joinable() ) // wait on cleanup thread here.
{
m_thread.join();
}
}
void CShareMgr::_CleanupThread()
{
while ( true )
{
boost::unique_lock< boost::mutex > lock( m_cvMutex );
if ( m_cv.wait_for( lock, boost::chrono::minutes( 1 ), [ this ] { return !m_fRunning; } ) )
return;
lock.unlock();
_CleanupThreadVolatile();
}
}
void CShareMgr::_CleanupThreadVolatile() volatile
{
std::vector
Em sex., 26 de abr. de 2024 Ã s 13:51, David Bien via Boost
escreveu: Under Linux when BOOST_THREAD_HAS_EINTR_BUG is defined we SIGABRT at this:
~mutex() { BOOST_VERIFY(!posix::pthread_mutex_destroy(&m)); }
What is the return value of pthread_mutex_destroy here?
How is the code for BOOST_THREAD_HAS_NO_EINTR_BUG? Are UNIX signals being involved?
It's used here: https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fboostorg%2Fthread%2Fblob%2Faec18d337f41d8e3081ee65f5cf3b5090179ab0e%2Finclude%2Fboost%2Fthread%2Fpthread%2Fpthread_helpers.hpp%23L17&data=05%7C02%7C%7C8a131f3fbb1546d5138208dc6615d40e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638497491169778552%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=X%2B767f7giYai7qMLtBCTd65AfHC2HKYAnCAHMciSoqU%3D&reserved=0https://github.com/boostorg/thread/blob/aec18d337f41d8e3081ee65f5cf3b5090179... Basically, the relevant code is: #ifdef BOOST_THREAD_HAS_EINTR_BUG BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS int pthread_mutex_destroy(pthread_mutex_t* m) { int ret; do { ret = ::pthread_mutex_destroy(m); } while (ret == EINTR); return ret; } #else BOOST_FORCEINLINE BOOST_THREAD_DISABLE_THREAD_SAFETY_ANALYSIS int pthread_mutex_destroy(pthread_mutex_t* m) { return ::pthread_mutex_destroy(m); } #endif The only scenario in which the former can return nonzero when the latter doesn't would be if it returns EINTR, and then tries to destroy the mutex again, and then get EINVAL because the mutex has already been destroyed. But this doesn't make sense because in this case the other function would have returned EINTR, which is also nonzero, so it should also fail the VERIFY. So I'm at a loss here. More printf debugging (printing the return values in both cases) is needed. _______________________________________________ Unsubscribe & other changes: https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Flists.boost.org%2Fmailman%2Flistinfo.cgi%2Fboost&data=05%7C02%7C%7C8a131f3fbb1546d5138208dc6615d40e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638497491169793535%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=%2BSvaxKUj05Yr91tn80uRbt%2BCRgK%2BnXuViPDrBTOVIU4%3D&reserved=0http://lists.boost.org/mailman/listinfo.cgi/boost