test1.cpp revision 12855:588919e0e4aa
1//---------------------------------------------------------------------- 2// Copyright 2009 Cadence Design Systems, Inc. 3// All Rights Reserved Worldwide 4//---------------------------------------------------------------------- 5 6#include <systemc.h> 7 8class my_exception { 9public: 10 my_exception(const char* s) : s_(s) { } 11 const char* message() { return s_.c_str(); } 12protected: 13 std::string s_; 14}; 15 16SC_MODULE(top) { 17public: 18 SC_CTOR(top) { 19 SC_THREAD(victim); 20 h = sc_get_current_process_handle(); 21 SC_THREAD(perpetrator); 22 } 23 24 void victim() { 25 try { 26 cerr << sc_time_stamp() << ": starting victim thread" << endl; 27 ::sc_core::wait(100, SC_NS); 28 } 29 catch (my_exception& x) { 30 cerr << sc_time_stamp() << ": in victim thread, caught exception " 31 << x.message() << ", exiting" << endl; 32 return; 33 } 34 } 35 36 void perpetrator() { 37 wait(10, SC_NS); 38 cerr << sc_time_stamp() 39 << ": in perpetrator throwing exception in victim " 40 << endl; 41 h.throw_it(my_exception("from pepetrator")); 42 cerr << sc_time_stamp() 43 << ": in perpetrator after throwing exception in victim " 44 << endl; 45 } 46 47protected: 48 sc_process_handle h; 49}; 50 51int sc_main (int argc, char *argv[]) 52{ 53 top t("top"); 54 sc_start(); 55 return 0; 56} 57 58