From bc0b1a78e5b5345282f9ce9017abcb7ceb6818ca Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Sat, 13 May 2017 14:07:54 +0200 Subject: [PATCH] common: workaround to start ASAN with recent glibc Issue: wait of the semaphore timedout. However semaphore was properly posted counter is 1. To workaround the issue, only throw an error if semaphore counter is 0. Note: I reduced the timeout to 100ms by threads to avoid huge startup delay Close #1939 --- common/src/Utilities/ThreadTools.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/common/src/Utilities/ThreadTools.cpp b/common/src/Utilities/ThreadTools.cpp index 649027b828..53cbb93ae2 100644 --- a/common/src/Utilities/ThreadTools.cpp +++ b/common/src/Utilities/ThreadTools.cpp @@ -256,12 +256,23 @@ void Threading::pxThread::Start() if (pthread_create(&m_thread, NULL, _internal_callback, this) != 0) throw Exception::ThreadCreationError(this).SetDiagMsg(L"Thread creation error: " + wxString(std::strerror(errno))); +#ifdef ASAN_WORKAROUND + // Recent Asan + libc6 do pretty bad stuff on the thread init => https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77982 + // + // In our case, the semaphore was posted (counter is 1) but thread is still + // waiting... So waits 100ms and checks the counter value manually + if (!m_sem_startup.WaitWithoutYield(wxTimeSpan(0, 0, 0, 100))) { + if (m_sem_startup.Count() == 0) + throw Exception::ThreadCreationError(this).SetDiagMsg(L"Thread creation error: %s thread never posted startup semaphore."); + } +#else if (!m_sem_startup.WaitWithoutYield(wxTimeSpan(0, 0, 3, 0))) { RethrowException(); // And if the thread threw nothing of its own: throw Exception::ThreadCreationError(this).SetDiagMsg(L"Thread creation error: %s thread never posted startup semaphore."); } +#endif // Event Rationale (above): Performing this semaphore wait on the created thread is "slow" in the // sense that it stalls the calling thread completely until the new thread is created