Tanja Posted July 31, 2013 Report Share Posted July 31, 2013 Hello, is there a way to create vectors of events (sc_event)?? Thank you Quote Link to comment Share on other sites More sharing options...
ralph.goergen Posted July 31, 2013 Report Share Posted July 31, 2013 Hi Tanja. A vector of events is not supported (afaik). You cannot use sc_vector because sc_event is not derived from sc_object. You cannot use std::vector<sc_event> because you are not allowed to copy sc_event objects. But: SystemC offers event lists (sc_event_or_list, sc_event_and_list). See: IEEE 1666-2011, Section 5.8 for more info. Greetings Ralph Quote Link to comment Share on other sites More sharing options...
Tanja Posted July 31, 2013 Author Report Share Posted July 31, 2013 Thanks Ralph. But the event lists won't help! I am looking for a way to generate a certain number of events depending on the number of modules i have. Let's assume, i have a top-module T1 with two modules: M1 with a thread process P1 and another one with a thread process P2. Process P2 is dynamically sensitive to an event ev1. P1 notify ev1 when it is executed. I want to instantiate another top-module T2 with the same modules and processes but here i need a different event as ev1. so Process P2 in T2 should wait for ev2 to be resumed. How can i achieved this without writing the same code twice? (P1 and P2 have to be in different modules) Thank you very much in advance! Quote Link to comment Share on other sites More sharing options...
ralph.goergen Posted July 31, 2013 Report Share Posted July 31, 2013 Three ideas, but actually none of it really satisfying. 1.: Use an std::vector<sc_event*>. The pointers work in std::vector because they are default constructible and copyable. Then you can allocate the necessary events dynamically in a for-loop (with all the drawbacks of pointers and dynamic memory allocation). 2.: Use a dummy module only containing a single event: SC_MODULE(ev_holder){sc_event ev;}; Then, you can use an sc_vector of these modules. 3.: sc_vector<sc_event> (with custom creator?) sc_vector works in some circumstances with objects that are nor sc_objects. Since sc_event has a constructor which takes a char* argument, it might work. But I am not sure. Greetings Ralph Quote Link to comment Share on other sites More sharing options...
Tanja Posted August 1, 2013 Author Report Share Posted August 1, 2013 Hi Ralph, 3. it had tried it already. it does't work. sc_event cannot acces the private member of sc_event! 1. I implemented it. it works for the first array. I added a second one, now i got an exception: one heap has been corrupted! The code stops by the fonction void free(pblock) What i am doing wrong? std::vector< sc_core::sc_event* > ev_vector ; for (int i = 1; i<=n; i++) { std::string str = std::to_string((unsigned long long)i); str = "event_nr" + str; ev_vector.push_back(new sc_core::sc_event(str.c_str())); } in P1: ev_vector.at(pos)->notify(); in P2: wait( *ev_vector.at(pos) ) Greetings Quote Link to comment Share on other sites More sharing options...
ralph.goergen Posted August 1, 2013 Report Share Posted August 1, 2013 Hard to say. That is the pain with pointers and dynamic memory allocation. Do you delete the allocated events manually? Where and how? Some unintended assignment to the pointers? How do you create and fill the second vector? Two further hints: 1: Version 3 might work if you initialize the sc_vector at construction time. Individual assignment doesn't work since you are not allowed to copy events. sc_vector<sc_event> sc_ev_vec("ev_vector",n); 2: Naming the events in your solution is easier with stringstreams instead of strings. #include <iomanip> for (int i = 1; i<=n; ++i) { std::stringstream str; str << "event_nr" << std::setfill('0') << std::setw(5) << i; ev_vector.push_back(new sc_core::sc_event(str.str().c_str())); } Quote Link to comment Share on other sites More sharing options...
Tanja Posted August 1, 2013 Author Report Share Posted August 1, 2013 1. I do not delete the allocated events! Should i? i need them till the end of the simulation 2. no assignment to the pointers 3. as same as i did for the first pointer Quote Link to comment Share on other sites More sharing options...
ralph.goergen Posted August 1, 2013 Report Share Posted August 1, 2013 It is not necessary to delete the events because the program exits at the end of the simulation. But someone tries to free some memory. My only remaining idea is to try to locate the problem in a debugger. gdb [program] catch throw (to stop at the point where the exception is thrown) run bt (to show the backtrace) Is it possible to post a striped-down version of your example? Quote Link to comment Share on other sites More sharing options...
Tanja Posted May 7, 2014 Author Report Share Posted May 7, 2014 Hi Ralph, version 3 worked fine. Thank you vry much 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.