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

fix #4763: shell not finishing before hard timeout

The timer thread for the hard timeout was leaking and thus the thread only exited on timeout
This commit is contained in:
Nuno Lopes 2020-10-30 10:01:09 +00:00
parent 0e1def5bd6
commit 1730bc7c7f
4 changed files with 9 additions and 9 deletions

View file

@ -398,6 +398,7 @@ int STD_CALL main(int argc, char ** argv) {
default: default:
UNREACHABLE(); UNREACHABLE();
} }
disable_timeout();
memory::finalize(); memory::finalize();
#ifdef _WINDOWS #ifdef _WINDOWS
_CrtDumpMemoryLeaks(); _CrtDumpMemoryLeaks();

View file

@ -20,6 +20,7 @@ Revision History:
--*/ --*/
#include "util/scoped_timer.h" #include "util/scoped_timer.h"
#include "util/mutex.h"
#include "util/util.h" #include "util/util.h"
#include <chrono> #include <chrono>
#include <climits> #include <climits>
@ -27,10 +28,6 @@ Revision History:
#include <mutex> #include <mutex>
#include <thread> #include <thread>
#include <vector> #include <vector>
#include <atomic>
struct scoped_timer_state { struct scoped_timer_state {
std::thread * m_thread { nullptr }; std::thread * m_thread { nullptr };
@ -43,7 +40,7 @@ struct scoped_timer_state {
static std::vector<scoped_timer_state*> available_workers; static std::vector<scoped_timer_state*> available_workers;
static std::mutex workers; static std::mutex workers;
static std::atomic<unsigned> num_workers(0); static atomic<unsigned> num_workers(0);
static void thread_func(scoped_timer_state *s) { static void thread_func(scoped_timer_state *s) {
workers.lock(); workers.lock();
@ -121,8 +118,7 @@ scoped_timer::~scoped_timer() {
void scoped_timer::finalize() { void scoped_timer::finalize() {
unsigned deleted = 0; unsigned deleted = 0;
unsigned tries = 0; while (deleted < num_workers) {
while (deleted < num_workers && tries < 10) {
workers.lock(); workers.lock();
for (auto w : available_workers) { for (auto w : available_workers) {
w->work = 2; w->work = 2;
@ -138,6 +134,5 @@ void scoped_timer::finalize() {
delete w->m_thread; delete w->m_thread;
delete w; delete w;
} }
++tries;
} }
} }

View file

@ -47,10 +47,13 @@ static g_timeout_eh eh;
void set_timeout(long ms) { void set_timeout(long ms) {
SASSERT(!g_timeout); SASSERT(!g_timeout);
// this is leaked, but since it's only used in the shell, it's ok
g_timeout = new scoped_timer(ms, &eh); g_timeout = new scoped_timer(ms, &eh);
} }
void disable_timeout() {
delete g_timeout;
}
void register_on_timeout_proc(void (*proc)()) { void register_on_timeout_proc(void (*proc)()) {
g_on_timeout = proc; g_on_timeout = proc;
} }

View file

@ -21,4 +21,5 @@ Revision History:
void register_on_timeout_proc(void (*proc)()); void register_on_timeout_proc(void (*proc)());
void set_timeout(long ms); void set_timeout(long ms);
void disable_timeout();