test03.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 test03.cpp -- Test sc_join as gating mechanism for a process awaiting the 23 demise of its child processes. 24 25 Original Author: Andy Goodrich, Forte Design Systems, 18 April 2005 26 27 *****************************************************************************/ 28 29/***************************************************************************** 30 31 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 32 changes you are making here. 33 34 Name, Affiliation, Date: 35 Description of Modification: 36 37 *****************************************************************************/ 38 39#define SC_INCLUDE_DYNAMIC_PROCESSES 40#include "systemc.h" 41 42SC_MODULE(TB) 43{ 44 SC_CTOR(TB) 45 { 46 SC_THREAD(abc); 47 sensitive << m_clk.pos(); 48 } 49 void abc() 50 { 51 for ( int i = 0; i < 3; i++ ) 52 { 53 cout << "Time Spawn Start Stop " << endl; 54 cout << "----- ----- ----- ----" << endl; 55 int ii = 2; 56 int spawn_i; 57 int spawn_n = 8; 58 sc_spawn_options options; 59 sc_join join; 60 options.set_sensitivity(&m_clk.pos()); 61 for ( spawn_i = 0; spawn_i < spawn_n; spawn_i++ ) 62 { 63 int process_i = spawn_i + i * spawn_n; 64 cout << sc_time_stamp() << " " << process_i << endl; 65 join.add_process(sc_spawn( 66 sc_bind(&TB::process, this, sc_ref(process_i)), 67 sc_gen_unique_name("pipe"), &options ) ); 68 sc_core::wait(ii); 69 } 70 cout << sc_time_stamp() << " waiting for termination of " 71 << join.process_count() << " processes" << endl; 72 join.wait(); 73 cout << sc_time_stamp() << " back from termination wait " << endl; 74 } 75 } 76 void process( int& instance ) 77 { 78 int i = instance; 79 cout << sc_time_stamp() << " " << i << endl; 80 wait(6); 81 cout << sc_time_stamp() << " " << i << endl; 82 } 83 sc_in<bool> m_clk; 84}; 85 86 87int sc_main(int argc, char* argv[]) 88{ 89 sc_clock clock; 90 TB tb("tb"); 91 92 tb.m_clk(clock); 93 sc_start(100, SC_NS); 94 cout << "Program completed." << endl; 95 return 0; 96} 97