112855Sgabeblack@google.com#define SC_INCLUDE_DYNAMIC_PROCESSES
212855Sgabeblack@google.com
312855Sgabeblack@google.com#include <systemc>
412855Sgabeblack@google.comusing namespace sc_core;
512855Sgabeblack@google.comusing namespace sc_dt;
612855Sgabeblack@google.comusing std::cout;
712855Sgabeblack@google.comusing std::endl;
812855Sgabeblack@google.com
912855Sgabeblack@google.com// 19) Call to sc_spawn in what would have been the final update phase...
1012855Sgabeblack@google.com
1112855Sgabeblack@google.comsc_event ev;
1212855Sgabeblack@google.com
1312855Sgabeblack@google.comstruct Prim: sc_prim_channel, sc_interface
1412855Sgabeblack@google.com{
1512855Sgabeblack@google.com  Prim() : count(0) {}
1612855Sgabeblack@google.com
1712855Sgabeblack@google.com  void write() {
1812855Sgabeblack@google.com    request_update();
1912855Sgabeblack@google.com  }
2012855Sgabeblack@google.com  void update() {
2112855Sgabeblack@google.com    sc_spawn(sc_bind(&Prim::spawned_proc, this));
2212855Sgabeblack@google.com  }
2312855Sgabeblack@google.com  void spawned_proc()
2412855Sgabeblack@google.com  {
2512855Sgabeblack@google.com    ++ count;
2612855Sgabeblack@google.com    ev.notify(5, SC_NS);
2712855Sgabeblack@google.com  }
2812855Sgabeblack@google.com  const sc_event& default_event() const { return ev; }
2912855Sgabeblack@google.com  int count;
3012855Sgabeblack@google.com};
3112855Sgabeblack@google.com
3212855Sgabeblack@google.comSC_MODULE(M)
3312855Sgabeblack@google.com{
3412855Sgabeblack@google.com  Prim prim;
3512855Sgabeblack@google.com  SC_CTOR(M)
3612855Sgabeblack@google.com    : ME_count(0)
3712855Sgabeblack@google.com  {
3812855Sgabeblack@google.com    SC_THREAD(T);
3912855Sgabeblack@google.com    SC_METHOD(ME);
4012855Sgabeblack@google.com      sensitive << prim;
4112855Sgabeblack@google.com      dont_initialize();
4212855Sgabeblack@google.com  }
4312855Sgabeblack@google.com  void T()
4412855Sgabeblack@google.com  {
4512855Sgabeblack@google.com    wait(10, SC_NS);
4612855Sgabeblack@google.com    prim.write();
4712855Sgabeblack@google.com    sc_assert(sc_time_stamp() == sc_time(10, SC_NS));
4812855Sgabeblack@google.com  }
4912855Sgabeblack@google.com  void ME()
5012855Sgabeblack@google.com  {
5112855Sgabeblack@google.com    ++ ME_count;
5212855Sgabeblack@google.com    sc_assert(sc_time_stamp() == sc_time(15, SC_NS));
5312855Sgabeblack@google.com  }
5412855Sgabeblack@google.com  int ME_count;
5512855Sgabeblack@google.com};
5612855Sgabeblack@google.com
5712855Sgabeblack@google.comstruct Top: sc_module
5812855Sgabeblack@google.com{
5912855Sgabeblack@google.com  M *m;
6012855Sgabeblack@google.com  Top(sc_module_name)
6112855Sgabeblack@google.com  {
6212855Sgabeblack@google.com    m = new M("m");
6312855Sgabeblack@google.com  }
6412855Sgabeblack@google.com};
6512855Sgabeblack@google.com
6612855Sgabeblack@google.comint sc_main(int argc, char* argv[])
6712855Sgabeblack@google.com{
6812855Sgabeblack@google.com  cout << "Should be silent..." << endl;
6912855Sgabeblack@google.com
7012855Sgabeblack@google.com  Top top("top");
7112855Sgabeblack@google.com  sc_start();
7212855Sgabeblack@google.com
7312855Sgabeblack@google.com  sc_assert(top.m->prim.count == 1);
7412855Sgabeblack@google.com  sc_assert(top.m->ME_count == 1);
7512855Sgabeblack@google.com
7612855Sgabeblack@google.com
7712855Sgabeblack@google.com  cout << endl << "Success" << endl;
7812855Sgabeblack@google.com  return 0;
7912855Sgabeblack@google.com}
80