living_dead_bug.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// living_dead_bug.cpp -- test for
21//
22//  Original Author: John Aynsley, Doulus
23//
24// MODIFICATION LOG - modifiers, enter your name, affiliation, date and
25//
26
27//
28
29#define SC_INCLUDE_DYNAMIC_PROCESSES
30
31#include <systemc>
32
33using namespace sc_core;
34using std::cout;
35using std::endl;
36
37struct Top: sc_module
38{
39  Top(sc_module_name _name)
40  {
41    SC_THREAD(control);
42
43    SC_THREAD(target);
44      dont_initialize();
45      target_handle = sc_get_current_process_handle();
46
47    f0 = f1 = 0;
48  }
49
50  sc_process_handle target_handle;
51  int f0, f1;
52
53  void control()
54  {
55    // create another (orphaned) instance of "target"
56    {
57      sc_spawn_options opt;
58      opt.dont_initialize();
59      sc_spawn( sc_bind( &Top::target, this ), "dyn_target", &opt );
60    }
61
62    wait(10, SC_NS);
63    f0 = 1;
64    target_handle.kill();
65    f1 = 1;
66  }
67
68  void target()
69  {
70    sc_assert( false );  // FAILS!!!!!!
71  }
72
73  SC_HAS_PROCESS(Top);
74};
75
76int sc_main(int argc, char* argv[])
77{
78  Top top("top");
79
80  sc_start();
81
82  sc_assert( top.f0 );
83  sc_assert( top.f1 );
84
85  cout << endl << "Success" << endl;
86  return 0;
87}
88
89