Jump to content
Sign in to follow this  
flashman

Accessing to a shared variable

Recommended Posts

Hi all.

 

I'm testing some codes to better understanding tlm.

 

In this moment I have a block with this variable :

 

    std::map <tlm::tlm_generic_payload*, unsigned int>  queue;

 

Basically a place when I store my transactions using trans pointer as key.

 

This variable is accessed by 2 threads. On as input and one as output.  Input is fast, output is slow.

 

Threads Input wait until a location (I check my max size) is free and fill it.

 

In system C I used sc_mutex to check lock and check it every X ns (wait(X,SC_NS)).  In tlm I don't want to used fixed time but wait until a location is free.

 

Is there a simple approach to do this  or I need to use sc_mutex or similar to share variable among multiple process ?

 

Thanks for every suggestion. I need it!

Share this post


Link to post
Share on other sites

Thank you Kartik for your suggestion.

 

sc_fifo match my requirements for sharing but I need to remove every element in every order. This is why I choosed std::map with a key.

 

I insert my elements and remove in every order. Only at start of simulation I fill my queue in order.

Share this post


Link to post
Share on other sites

Thank you Kartik for your suggestion.

 

sc_fifo match my requirements for sharing but I need to remove every element in every order. This is why I choosed std::map with a key.

 

I insert my elements and remove in every order. Only at start of simulation I fill my queue in order.

 

for your case, I would choose to design a primitive channel to realize your requirement. This channel should be very similar to the sc_fifo, except that the element can be read/written with a given index or a specific order. I don't think using the build-in language elements to do this is a elegant way, since you may be changing the semantics of these elements. 

 

To implement it, just take a look at the sc_fifo implement.

 

/Kenny

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×