3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-07 18:05:21 +00:00

fix for spurious wakeups in scoped_timer (#6102)

This commit is contained in:
Felix Kohlgrüber 2022-06-22 11:50:19 +02:00 committed by GitHub
parent 41deed59a3
commit a7b41c49fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 14 deletions

View file

@ -80,27 +80,20 @@ scoped_timer::scoped_timer(unsigned ms, event_handler * eh) {
return;
workers.lock();
bool new_worker = false;
if (available_workers.empty()) {
// start new thead
workers.unlock();
s = new scoped_timer_state;
new_worker = true;
++num_workers;
s->work = WORKING;
}
else {
s = available_workers.back();
available_workers.pop_back();
s->work = WORKING;
workers.unlock();
}
s->ms = ms;
s->eh = eh;
s->m_mutex.lock();
if (new_worker) {
init_state(ms, eh);
s->m_thread = std::thread(thread_func, s);
}
else {
// re-use existing thread
s = available_workers.back();
available_workers.pop_back();
init_state(ms, eh);
workers.unlock();
s->cv.notify_one();
}
}
@ -148,3 +141,10 @@ void scoped_timer::finalize() {
num_workers = 0;
available_workers.clear();
}
void scoped_timer::init_state(unsigned ms, event_handler * eh) {
s->ms = ms;
s->eh = eh;
s->m_mutex.lock();
s->work = WORKING;
}

View file

@ -29,6 +29,8 @@ public:
~scoped_timer();
static void initialize();
static void finalize();
private:
void init_state(unsigned ms, event_handler * eh);
};
/*