red_dandelion Posted November 4, 2023 Report Share Posted November 4, 2023 Codes as follows: #include <systemc> using namespace sc_core; SC_MODULE(DELTA) { sc_in<bool> clk; int y = 1; SC_CTOR(DELTA) { SC_THREAD(add_y); sensitive << clk.pos(); SC_THREAD(multiply_y); sensitive << clk.pos(); //dont_initialize(); } void add_y() { // y += 2 happens after a delta cycle while (true) { std::cout << "add_y0 stamp: " << sc_time_stamp() << std::endl; wait(SC_ZERO_TIME); std::cout << "add_y: " << y << " + 2" << " = "; y += 2; std::cout << y << std::endl; std::cout << "add_y stamp: " << sc_time_stamp() << std::endl; wait(); } } void multiply_y() { while (true) { std::cout << "multiply_y: " << y << " * 3" << " = "; y *= 3; std::cout << y << std::endl; std::cout << "multiply_y stamp: " << sc_time_stamp() << std::endl; wait(); } } }; int sc_main(int, char* []) { sc_clock clk("clock", 5, SC_SEC); DELTA delta("delta"); delta.clk(clk); sc_start(30, SC_SEC); return 0; } output: add_y0 stamp: 0 s multiply_y: 1 * 3 = 3 multiply_y stamp: 0 s multiply_y: 3 * 3 = 9 multiply_y stamp: 0 s add_y: 9 + 2 = 11 add_y stamp: 0 s multiply_y: 11 * 3 = 33 multiply_y stamp: 5 s add_y0 stamp: 5 s add_y: 33 + 2 = 35 add_y stamp: 5 s multiply_y: 35 * 3 = 105 multiply_y stamp: 10 s add_y0 stamp: 10 s add_y: 105 + 2 = 107 add_y stamp: 10 s I am confused for function multiply_y execute twice, If I make the "dont_initialize();" valid, the function only execute once! Appreciate Any one who can explain why. Quote Link to comment Share on other sites More sharing options...
maehne Posted November 6, 2023 Report Share Posted November 6, 2023 During initialization, all processes are executed once except those, which have been marked with dont_initialize(). See IEEE 1666-2011, clause "4.2.1.1 Initialization phase" for details. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.