thundium Posted May 19, 2014 Report Share Posted May 19, 2014 Hi All: I got a given SystemC code running without end_of_simulation called. And I know "end_of_simulation" won't be called if sc_stop is not called. I debug into the code and see following situation. Code looks like void thread_a() //it is a sc thread { while(xxx) { wait(sc_time(x,SC_NS)); break 1 cout<<"xxxxx"<<endl; break 2 ---logics---- } sc_stop; } The last time I was stopped at breakpoint 1, then I did step next. Then instead of stopping at breakpoint 2 , I stopped at sc_main after sc_start. So it looks like the entire thread is stopped by others? What else than "sc_stop" can terminate the thread? Since my code in "end_of_simulation" is not triggered, I am sure that there is no other sc_stop in my programme that calling sc_stop. So what can be the backend hand doing that? Thanks a lot for all your help Quote Link to comment Share on other sites More sharing options...
thundium Posted May 19, 2014 Author Report Share Posted May 19, 2014 I see, seems the sc_start(xxx ns) will terminate everything without calling sc_stop Quote Link to comment Share on other sites More sharing options...
apfitch Posted May 19, 2014 Report Share Posted May 19, 2014 The LRM (section 4.4.4) specifies that end_of_simulation() will be called either after sc_stop(), or if sc_main is not used. Sometimes people call sc_stop() after sc_start() just to trigger the end_of_simulation() callback. Regarding your first question, you've left out the vital piece of information! What is "xxx" in wait(xxx). If it is the word true, then of course the loop will never exit and sc_stop() will never get called. regards Alan maehne 1 Quote Link to comment Share on other sites More sharing options...
David Black Posted May 20, 2014 Report Share Posted May 20, 2014 I typically use the following code following sc_start(): sc_start(); if (not sc_end_of_simulation_invoked()) { SC_REPORT_INFO(MSGID,"ERROR: Simulation stopped without explicit sc_stop()"); sc_stop(); }//endif That way I always know end_of_simulation() will be invoked. I also put try/catch blocks around both the design instantiation and sc_start itself to be certain I know why my simulation stopped. std::unique_ptr<Top_module> top_instance; //NOTE: Use std::auto_ptr<> for pre-C++11 try { top_instance.reset( new Top_module("top_instance") ); } catch (std::exception& e) { SC_REPORT_ERROR(MSGID,(string(e.what())+" Please fix elaboration errors and retry.").c_str()); return 1; } catch (...) { SC_REPORT_ERROR(MSGID,"Caught exception during elaboration"); return 1; }//endtry // Simulate try { SC_REPORT_INFO(MSGID,"Starting kernal"); sc_start(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<< START SIMULATOR SC_REPORT_INFO(MSGID,"Exited kernal"); } catch (std::exception& e) { SC_REPORT_WARNING(MSGID,(string("Caught exception ")+e.what()).c_str()); } catch (...) { SC_REPORT_ERROR(MSGID,"Caught exception during simulation."); }//endtry maehne 1 Quote Link to comment Share on other sites More sharing options...
biplab77 Posted May 12, 2015 Report Share Posted May 12, 2015 @apfitch and @ david, i understood the concept of end of simulation... But i had the query that is there a way to stop the simulation at any point under some conditions?? Can i use sc_stop() any where in the code or it is mandatory to use it in main(). WellThe LRM (section 4.4.4) specifies that end_of_simulation() will be called either after sc_stop(), or if sc_main is not used. Can i use sc_stop at any part of my program?? Quote Link to comment Share on other sites More sharing options...
apfitch Posted May 12, 2015 Report Share Posted May 12, 2015 See the 1666-2011 Language Reference Manual, section 4.5.3 - especially the last paragraph on page 29. The LRM is your friend :-) Alan maehne 1 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.