OLD_kill_reset.cpp revision 12855:588919e0e4aa
1#define SC_INCLUDE_DYNAMIC_PROCESSES
2
3#include <systemc>
4
5using namespace sc_core;
6using std::cout;
7using std::endl;
8
9struct M3: sc_module
10{
11  M3(sc_module_name _name)
12  {
13    SC_THREAD(ticker);
14    SC_THREAD(calling);
15    SC_THREAD(target);
16      t = sc_get_current_process_handle();
17  }
18
19  sc_process_handle t;
20  sc_event ev;
21  int count;
22
23  void ticker()
24  {
25    for (;;)
26    {
27      wait(10, SC_NS);
28      ev.notify();
29    }
30  }
31
32  void calling()
33  {
34    wait(15, SC_NS);
35    // Target runs at time 10 NS due to notification
36    sc_assert( count == 1 );
37
38    wait(10, SC_NS);
39    // Target runs again at time 20 NS due to notification
40    sc_assert( count == 2 );
41
42    t.reset();
43    // Target reset immediately at time 25 NS
44    sc_assert( count == 0 );
45
46    wait(10, SC_NS);
47    // Target runs again at time 30 NS due to notification
48    sc_assert( count == 1 );
49
50    t.kill();
51    // Target killed immediately at time 35 NS
52    sc_assert( t.terminated() );
53
54    sc_stop();
55  }
56
57  void target()
58  {
59    cout << "Target called/reset at " << sc_time_stamp() << endl;
60    count = 0;
61    for (;;)
62    {
63      wait(ev);
64      cout << "Target awoke at " << sc_time_stamp() << endl;
65      ++count;
66    }
67  }
68
69  SC_HAS_PROCESS(M3);
70};
71
72int sc_main(int argc, char* argv[])
73{
74  M3 m("m");
75
76  sc_start();
77
78  return 0;
79}
80
81