12struct async_thread : sc_core::sc_prim_channel {
14 async_thread() =
default;
16 explicit async_thread(
const char* nm)
17 : sc_core::sc_prim_channel{nm} {}
24 void start(std::function<sc_core::sc_time()>
const& f) {
25 SCCTRACE(SCMOD) <<
"Starting new thread";
26 t1 = std::move(std::thread([
this, f]() {
28 finish_time.store(f().value());
29 async_request_update();
30 }
catch(std::future_error& e) {
36 const sc_core::sc_event& thread_finish_event()
const {
return finish_event; }
39 void update()
override {
41 auto end_time = sc_core::sc_time::from_value(finish_time.load());
42 finish_event.notify(end_time > sc_core::sc_time_stamp() ? end_time - sc_core::sc_time_stamp() : sc_core::SC_ZERO_TIME);
44 SCCTRACEALL(SCOBJ) <<
"Finished execution of thread";
47 sc_core::sc_event finish_event;
48 std::atomic<uint64_t> finish_time;