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
58
59
60
61
62
63
64
65
66
67
68
|
#define SC_INCLUDE_DYNAMIC_PROCESSES
#include <systemc>
using namespace sc_core;
using namespace sc_dt;
using std::cout;
using std::endl;
// 3) terminated_event()
SC_MODULE(M)
{
SC_CTOR(M)
{
SC_THREAD(T);
}
void T()
{
sc_process_handle h1 = sc_spawn(sc_bind(&M::proc, this, 2));
sc_process_handle h2 = sc_spawn(sc_bind(&M::proc, this, 3));
sc_process_handle h3 = sc_spawn(sc_bind(&M::proc, this, 1));
sc_assert(sc_time_stamp() == sc_time(0, SC_NS));
wait(h1.terminated_event() & h2.terminated_event() & h3.terminated_event());
sc_assert(sc_time_stamp() == sc_time(3, SC_NS));
if (h1.valid()) sc_assert (h1.terminated());
if (h2.valid()) sc_assert (h2.terminated());
if (h3.valid()) sc_assert (h3.terminated());
h1 = sc_spawn(sc_bind(&M::proc, this, 10));
h2 = sc_spawn(sc_bind(&M::proc, this, 30));
h3 = sc_spawn(sc_bind(&M::proc, this, 20));
sc_assert(sc_time_stamp() == sc_time(3, SC_NS));
wait(h1.terminated_event() | h2.terminated_event() | h3.terminated_event());
sc_assert(sc_time_stamp() == sc_time(13, SC_NS));
sc_assert(h2.valid());
sc_assert( !h2.terminated() );
sc_assert(h3.valid());
sc_assert( !h3.terminated() );
wait(h2.terminated_event() & h3.terminated_event());
sc_assert(sc_time_stamp() == sc_time(33, SC_NS));
}
void proc(int delay)
{
wait(delay * sc_time(1, SC_NS));
}
};
SC_MODULE(Top)
{
M *m;
SC_CTOR(Top)
{
m = new M("m");
}
};
int sc_main(int argc, char* argv[])
{
cout << "Should be silent..." << endl;
Top top("top");
sc_start();
cout << endl << "Success" << endl;
return 0;
}
|