3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-01-24 19:14:00 +00:00

#7418 - circumvent use of timer threads to make WASM integration of z3 easier

The scoped_timer uses a std::therad. Spawning this thread fails in cases of WASM.
Instead of adapting builds and using async features at the level of WASM and the client, we expose a specialized version of z3 that doesn't use threads at all, neither for solvers nor for timers.
The tradeoff is that the periodic poll that checks for timeout directly queries the global clock each time.
We characterize it as based on polling.
This commit is contained in:
Nikolaj Bjorner 2024-11-21 11:20:05 -08:00
parent 94f0aff47f
commit 71bad7159b
8 changed files with 124 additions and 31 deletions

View file

@ -31,11 +31,7 @@ void finalize_rlimit() {
DEALLOC_MUTEX(g_rlimit_mux);
}
reslimit::reslimit():
m_cancel(0),
m_suspend(false),
m_count(0),
m_limit(std::numeric_limits<uint64_t>::max()) {
reslimit::reslimit() {
}
uint64_t reslimit::count() const {
@ -117,7 +113,7 @@ void reslimit::reset_cancel() {
void reslimit::inc_cancel() {
lock_guard lock(*g_rlimit_mux);
set_cancel(m_cancel+1);
set_cancel(m_cancel + 1);
}
void reslimit::dec_cancel() {
@ -133,3 +129,39 @@ void reslimit::set_cancel(unsigned f) {
m_children[i]->set_cancel(f);
}
}
#ifdef POLLING_TIMER
void reslimit::push_timeout(unsigned ms) {
m_num_timers++;
if (m_cancel > 0) {
++m_cancel;
return;
}
if (m_timeout_ms != 0) {
double ms_taken = 1000 * m_timer.get_seconds();
if (ms_taken > m_timeout_ms)
return;
if (m_timeout_ms - ms_taken < ms)
return;
}
m_timer = timer();
m_timeout_ms = ms;
}
void reslimit::inc_cancel(unsigned k) {
lock_guard lock(*g_rlimit_mux);
set_cancel(m_cancel + k);
}
void reslimit::auto_cancel() {
--m_num_timers;
dec_cancel();
}
#else
void reslimit::auto_cancel() {
UNREACHABLE();
}
#endif