diff --git a/systemc-components/common/include/qkmulti-quantum.h b/systemc-components/common/include/qkmulti-quantum.h index 521994d1..4eca03d0 100644 --- a/systemc-components/common/include/qkmulti-quantum.h +++ b/systemc-components/common/include/qkmulti-quantum.h @@ -20,8 +20,15 @@ class tlm_quantumkeeper_multi_quantum : public tlm_quantumkeeper_multithread sc_core::sc_time quantum = tlm_utils::tlm_quantumkeeper::get_global_quantum(); sc_core::sc_time next_quantum_boundary = sc_core::sc_time_stamp() + quantum; sc_core::sc_time now = get_current_time(); - if (next_quantum_boundary >= now) { + if (now < next_quantum_boundary) { return next_quantum_boundary - now; + } else if (now == next_quantum_boundary) { + // At the exact boundary: the CPU has used its quantum but hasn't + // exceeded it. Return a minimal non-zero value so sync() doesn't + // block. The timehandler will advance the kernel on the next delta + // cycle; blocking here risks a deadlock when sc_suspend_all() + // prevents next_time() from seeing the scheduled tick event. + return sc_core::sc_time(1, sc_core::SC_PS); } else { return sc_core::SC_ZERO_TIME; }