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