test10.cpp revision 12855:588919e0e4aa
1/***************************************************************************** 2 3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 4 more contributor license agreements. See the NOTICE file distributed 5 with this work for additional information regarding copyright ownership. 6 Accellera licenses this file to you under the Apache License, Version 2.0 7 (the "License"); you may not use this file except in compliance with the 8 License. You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 15 implied. See the License for the specific language governing 16 permissions and limitations under the License. 17 18 *****************************************************************************/ 19 20/***************************************************************************** 21 22 test10.cpp -- Testing proper process execution order for SC_METHOD murderer. 23 24 Original Author: Andy Goodrich 25 26 *****************************************************************************/ 27 28/***************************************************************************** 29 30 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 31 changes you are making here. 32 33 Name, Affiliation, Date: 34 Description of Modification: 35 36 *****************************************************************************/ 37// $Log: test10.cpp,v $ 38// Revision 1.2 2011/02/01 20:00:37 acg 39// Andy Goodrich: better messaging for output. 40// 41// Revision 1.1 2011/02/01 17:16:48 acg 42// Andy Goodrich: first check-in. 43// 44 45#define SC_INCLUDE_DYNAMIC_PROCESSES 46#include "systemc.h" 47 48SC_MODULE(DUT) 49{ 50 SC_CTOR(DUT) 51 { 52 SC_METHOD(killer); 53 sensitive << m_clk.pos(); 54 SC_CTHREAD(stimulus,m_clk.pos()); 55 SC_THREAD(thread0); 56 sensitive << m_clk.pos(); 57 m_thread0 = sc_get_current_process_handle(); 58 SC_THREAD(thread1); 59 sensitive << m_clk.pos(); 60 m_thread1 = sc_get_current_process_handle(); 61 SC_THREAD(thread2); 62 sensitive << m_clk.pos(); 63 m_thread2 = sc_get_current_process_handle(); 64 m_kill = false; 65 } 66 67 void killer() 68 { 69 if ( m_kill ) 70 { 71 cout << sc_time_stamp() << " killer: killing thread0 " << endl; 72 m_thread0.kill(); 73 cout << sc_time_stamp() << " killer: after killing thread0" << endl; 74 m_thread2.kill(); 75 cout << sc_time_stamp() << " killer: after killing thread2" << endl; 76 } 77 } 78 79 void thread0() 80 { 81 cout << sc_time_stamp() << " thread 0: initialization" << endl; 82 try { 83 for (;;) 84 { 85 wait(); 86 } 87 } 88 catch(sc_core::sc_unwind_exception& ex) 89 { 90 if ( !ex.is_reset() ) 91 { 92 cout << sc_time_stamp() << " thread0: received kill" << endl; 93 m_thread1.kill(); 94 cout << sc_time_stamp() << " thread0: after killing thread1" 95 << endl; 96 } 97 throw ex; 98 } 99 } 100 101 void thread1() 102 { 103 cout << sc_time_stamp() << " thread 1: initialization" << endl; 104 try { 105 for (;;) 106 { 107 wait(); 108 } 109 } 110 catch(sc_core::sc_unwind_exception& ex) 111 { 112 if ( !ex.is_reset() ) 113 { 114 cout << sc_time_stamp() << " thread1: received kill" << endl; 115 } 116 throw ex; 117 } 118 } 119 120 void thread2() 121 { 122 cout << sc_time_stamp() << " thread 2: initialization" << endl; 123 try { 124 for (;;) 125 { 126 wait(); 127 } 128 } 129 catch(sc_core::sc_unwind_exception& ex) 130 { 131 if ( !ex.is_reset() ) 132 { 133 cout << sc_time_stamp() << " thread2: received kill" << endl; 134 } 135 throw ex; 136 } 137 } 138 139 void stimulus() 140 { 141 for (;;) 142 { 143 wait(); 144 wait(); 145 wait(); 146 wait(); 147 cout << sc_time_stamp() << " stimulus setting kill" << endl; 148 m_kill = true; 149 wait(); 150 m_kill = false; 151 wait(); 152 wait(); 153 sc_stop(); 154 } 155 } 156 157 sc_in<bool> m_clk; 158 bool m_kill; 159 sc_process_handle m_thread0; 160 sc_process_handle m_thread1; 161 sc_process_handle m_thread2; 162}; 163 164int sc_main(int argc, char* argv[]) 165{ 166 sc_clock clock; 167 DUT dut("dut"); 168 169 dut.m_clk(clock); 170 171 sc_start(); 172 173 cout << "Program completed" << endl; 174 return 0; 175} 176