SystemC 2.3:throw_it

SystemC 2.3にて追加された「throw_it」についてです。

  • サンプルコード
 # include <stdio.h>
 # include <systemc.h>

SC_MODULE( hoge ){

  std::exception    ex;
  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);
    t.reset();

    wait(10, SC_NS);
    ev.notify();
    t.throw_it(ex);

    wait(10, SC_NS);
    t.kill();
    assert( t.terminated() );

    wait(10, SC_NS);
    ev.notify();
  }

  void target(){
     q = 0;
     while (1) {
       try {
         wait(ev);
         ++q;
         cout << sc_time_stamp();
         cout << " q = " << q << endl;
       }
       catch (const std::exception& e)
       {
         cout << "catch Exception" << endl;
         return;
       }
     }
  }
};

int sc_main(int argc, char *argv[]) {

  hoge mhoge("hoge");
  sc_start(500, sc_core::SC_NS);

  return 0;
}
  • 実行結果
$> ./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
catch Exception

Fatal: (F539) sc_unwind_exception not re-thrown during kill/reset: hoge.target
In file: ../../../../src/sysc/kernel/sc_except.cpp:67
In process: hoge.target @ 20 ns
中止 (コアダンプ)