Jump to content



Recommended Posts

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.




Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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. 




Link to comment
Share on other sites

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:


in P2:

wait( *ev_vector.at(pos) )



Link to comment
Share on other sites

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()));
Link to comment
Share on other sites

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) 


bt (to show the backtrace) 


Is it possible to post a striped-down version of your example?

Link to comment
Share on other sites

  • 9 months later...

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...