Jump to content

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!

Link to comment
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.

Link to comment
Share on other sites

  • 2 months later...

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

Link to comment
Share on other sites

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.

Guest
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...