mirror of
https://github.com/verilator/verilator.git
synced 2025-01-19 12:54:02 +00:00
Fix attempted to destroy locked thread pool error (#5040)
This commit is contained in:
parent
5601056ed0
commit
d1b45b8d32
@ -115,6 +115,7 @@ class V3ThreadPool final {
|
||||
// CONSTRUCTORS
|
||||
V3ThreadPool() = default;
|
||||
~V3ThreadPool() {
|
||||
m_shutdown = true;
|
||||
if (m_multithreadingSuspended) {
|
||||
// Ideally we shouldn't deal with this and just call the std::abort. However,
|
||||
// std::exit(0) (which invokes this destructor) is called in multiple places with
|
||||
@ -140,11 +141,15 @@ class V3ThreadPool final {
|
||||
}
|
||||
|
||||
bool m_mutex_locked = m_mutex.try_lock();
|
||||
// try_lock can sometimes spontaneously fail even when mutex is not locked,
|
||||
// make sure this isn't the case
|
||||
for (int i = 0; i < VL_LOCK_SPINS; ++i) {
|
||||
using namespace std::chrono_literals;
|
||||
// try to obtain lock with timeout
|
||||
// we need to wait for workers to start waiting
|
||||
// on condition variable to perform destruction
|
||||
constexpr int spins = 1s / 1ms;
|
||||
for (int i = 0; i < spins; ++i) {
|
||||
if (VL_LIKELY(m_mutex_locked)) break;
|
||||
VL_CPU_RELAX();
|
||||
std::this_thread::sleep_for(1ms);
|
||||
|
||||
m_mutex_locked = m_mutex.try_lock();
|
||||
}
|
||||
if (VL_UNCOVERABLE(!m_mutex_locked)) {
|
||||
|
Loading…
Reference in New Issue
Block a user