SystemC 2.3 : sc_starvation_policy
SystemC 2.3から追加になっている機能になります。
sc_start()時に、sc_starvation_policyを指定できます。
- 4.2.1 Function declarations より引用
enum sc_starvation_policy {
SC_RUN_TO_TIME,
SC_EXIT_ON_STARVATION
};
default値は「SC_RUN_TO_TIME」です。
- サンプルコード
#include <stdio.h> #include <systemc.h> SC_MODULE( hoge ){ sc_event ev; sc_process_handle t; int q; SC_CTOR( hoge ) { SC_THREAD( calling ); SC_THREAD( target ); t = sc_get_current_process_handle(); } void calling(){ wait(10, SC_NS); ev.notify(); wait(10, SC_NS); ev.notify(); wait(10, SC_NS); ev.notify(); } void target(){ q = 0; while (1) { wait(ev); ++q; cout << sc_time_stamp(); cout << " q = " << q << endl; } } }; int sc_main(int argc, char *argv[]) { hoge mhoge("hoge"); sc_start(20, sc_core::SC_NS); // sc_start(500, sc_core::SC_NS, SC_EXIT_ON_STARVATION ); sc_start(500, sc_core::SC_NS, SC_RUN_TO_TIME); cout << sc_time_stamp(); cout << " : End of Simulation time" << endl; return 0; }
- SC_RUN_TO_TIMEの結果
$> ./main
SystemC 2.3.0-ASI --- Feb 16 2013 23:56:43
Copyright (c) 1996-2012 by all Contributors,
ALL RIGHTS RESERVED
10 ns q = 1
20 ns q = 2
30 ns q = 3
520 ns : End of Simulation time
- SC_EXIT_ON_STARVATIONの結果
$> ./main
SystemC 2.3.0-ASI --- Feb 16 2013 23:56:43
Copyright (c) 1996-2012 by all Contributors,
ALL RIGHTS RESERVED
10 ns q = 1
20 ns q = 2
30 ns q = 3
30 ns : End of Simulation time
結果の通りなんですが、「SC_EXIT_ON_STARVATION」の場合は
イベントが無い時点で終了します。
クロックなどの無限イベントがあると効果ないと思いますが、
シミュレーション終了時に余分な時間を除くことが出来ます。