#define SC_INCLUDE_DYNAMIC_PROCESSES #include namespace sc_utils { struct yieldable { void yield() { if( !proc_.valid() ) // lazy pingback instantiation { sc_spawn_options opt; opt.spawn_method(); opt.set_sensitivity(&ping_); proc_ = sc_spawn( sc_bind( &yieldable::yield_method, this ) , "yield_method", &opt ); } ping_.notify(); wait(pong_); } private: void yield_method() { pong_.notify(); } sc_event ping_; sc_event pong_; sc_process_handle proc_; }; } // namespace sc_utils struct test_yield : sc_module , sc_utils::yieldable { SC_CTOR(test_yield) { SC_THREAD(run); } void run() { std::cout << "delta: " << sc_delta_count() << std::endl; yield(); std::cout << "delta: " << sc_delta_count() << std::endl; } }; int sc_main(int, char*[] ) { test_yield top("test_yield"); sc_start(); return 0; }