SystemC 2.3:unwind (reset and kill)

前回の「reset/kill」を観測することができます。

  • サンプルコード
 #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);
    t.reset();

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

    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 sc_unwind_exception& e)
       {
          sc_assert( sc_is_unwinding()) ;
          if( e.is_reset() ) cout << "target was reset"  << endl;
          else               cout << "target was killed" << endl;
          //proc_handle.reset(); // Reset some other process
          throw e;
       }
     }
  }
};

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 --- Dec 14 2012 21:01:01
        Copyright (c) 1996-2012 by all Contributors,
        ALL RIGHTS RESERVED

10 ns q = 1
target was reset
30 ns q = 1
target was killed