/* * author: Philipp A. Hartmann, OFFIS, hartmann@offis.de * * program output: * * before spawn (in dut.method @ delta 0) * after spawn (in dut.method @ delta 0) * spawned (in dut.method.thread_p_0 @ delta 0) * before kill (in dut.method @ delta 1) * after kill (in dut.method @ delta 1) * kill received (in dut.method.thread_p_0 @ delta 1) * Killing process dut.method.thread_p_0 * */ #define SC_INCLUDE_DYNAMIC_PROCESSES #include void debug_msg( const char * msg ) { std::cout << msg << " (in " << sc_get_current_process_handle().name() << " @ delta " << sc_delta_count() << ")" << std::endl; } SC_MODULE(kill_test) { SC_CTOR(kill_test) { SC_METHOD(method); } void thread() { debug_msg( "spawned" ); try { wait( 10, SC_NS ); } catch ( ... ) { debug_msg( "kill received" ); throw; } debug_msg( "ended" ); } void method() { if( !h.valid() ) { debug_msg( "before spawn" ); h = sc_spawn( sc_bind( &kill_test::thread, this ) ); debug_msg( "after spawn" ); next_trigger( 5, SC_NS ); } else { debug_msg( "before kill " ); h.kill( SC_INCLUDE_DESCENDANTS ); debug_msg( "after kill " ); } } private: sc_process_handle h; }; int sc_main( int, char*[] ) { kill_test t("dut"); sc_start(); return 0; }