summaryrefslogtreecommitdiff
path: root/src/systemc/tests/systemc/kernel/process_control/throw_it/test1/test1.cpp
blob: 1a3ceb192748e895fe20be7adac8e6d5bf568ee4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//----------------------------------------------------------------------
//   Copyright 2009 Cadence Design Systems, Inc.
//   All Rights Reserved Worldwide
//----------------------------------------------------------------------

#include <systemc.h>

class my_exception {
public:
  my_exception(const char* s) : s_(s) { }
  const char* message() { return s_.c_str(); }
protected:
  std::string s_;
};

SC_MODULE(top) {
public:
  SC_CTOR(top) {
    SC_THREAD(victim);
    h = sc_get_current_process_handle();
    SC_THREAD(perpetrator);
  }

  void victim() {
    try {
      cerr << sc_time_stamp() << ": starting victim thread" << endl;
      ::sc_core::wait(100, SC_NS);
    }
    catch (my_exception& x) {
      cerr << sc_time_stamp() << ": in victim thread, caught exception "
           << x.message() << ", exiting" << endl;
      return;
    }
  }

  void perpetrator() {
    wait(10, SC_NS);
    cerr << sc_time_stamp() 
         << ": in perpetrator throwing exception in victim " 
         << endl;
    h.throw_it(my_exception("from pepetrator"));
    cerr << sc_time_stamp() 
         << ": in perpetrator after throwing exception in victim " 
         << endl;
  }

protected:
  sc_process_handle h;
};

int sc_main (int argc, char *argv[])
{
  top t("top");
  sc_start();
  return 0;
}