mirror of
https://github.com/Z3Prover/z3
synced 2025-04-07 18:05:21 +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:
parent
0e1def5bd6
commit
1730bc7c7f
|
@ -398,6 +398,7 @@ int STD_CALL main(int argc, char ** argv) {
|
|||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
disable_timeout();
|
||||
memory::finalize();
|
||||
#ifdef _WINDOWS
|
||||
_CrtDumpMemoryLeaks();
|
||||
|
|
|
@ -20,6 +20,7 @@ Revision History:
|
|||
--*/
|
||||
|
||||
#include "util/scoped_timer.h"
|
||||
#include "util/mutex.h"
|
||||
#include "util/util.h"
|
||||
#include <chrono>
|
||||
#include <climits>
|
||||
|
@ -27,10 +28,6 @@ Revision History:
|
|||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
|
||||
|
||||
|
||||
|
||||
struct scoped_timer_state {
|
||||
std::thread * m_thread { nullptr };
|
||||
|
@ -43,7 +40,7 @@ struct scoped_timer_state {
|
|||
|
||||
static std::vector<scoped_timer_state*> available_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) {
|
||||
workers.lock();
|
||||
|
@ -121,8 +118,7 @@ scoped_timer::~scoped_timer() {
|
|||
|
||||
void scoped_timer::finalize() {
|
||||
unsigned deleted = 0;
|
||||
unsigned tries = 0;
|
||||
while (deleted < num_workers && tries < 10) {
|
||||
while (deleted < num_workers) {
|
||||
workers.lock();
|
||||
for (auto w : available_workers) {
|
||||
w->work = 2;
|
||||
|
@ -138,6 +134,5 @@ void scoped_timer::finalize() {
|
|||
delete w->m_thread;
|
||||
delete w;
|
||||
}
|
||||
++tries;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,10 +47,13 @@ static g_timeout_eh eh;
|
|||
|
||||
void set_timeout(long ms) {
|
||||
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);
|
||||
}
|
||||
|
||||
void disable_timeout() {
|
||||
delete g_timeout;
|
||||
}
|
||||
|
||||
void register_on_timeout_proc(void (*proc)()) {
|
||||
g_on_timeout = proc;
|
||||
}
|
||||
|
|
|
@ -21,4 +21,5 @@ Revision History:
|
|||
void register_on_timeout_proc(void (*proc)());
|
||||
|
||||
void set_timeout(long ms);
|
||||
void disable_timeout();
|
||||
|
||||
|
|
Loading…
Reference in a new issue