Jump to content

tlm_fifo content safety

Recommended Posts



I am used to making containers with boost::shared_ptr<T> as a data type.

I expected tlm_fifo to have similar semantics to STL containers, such as copy on push (tlm_fifo::put)

But I am seeing a crash at end of sim when the tlm_fifo gets deleted with items still in it, and it looks like the structure under the tlm_fifo (circular_buffer) uses a placement new to allocate a new entry upon write(). This is bypassing the copy semantics of the shared_ptr and creating a wild pointer as a result.


First, is this a known problem? If it is, is there another suitable container for shared_ptr?

I basically need a queue with event notification and I'd rather not build my own deque with sc_event's


Thank you

Hervé Alexanian

Xilinx, inc.


Link to comment
Share on other sites

  • 2 weeks later...

Which version of SystemC/TLM are you using?  I'm afraid, there is a known issue in the 2.3.1 circular_buffer implementation.  When the fifo is destroyed while there are still elements in it, the loop over the "to-be-cleared" items does not start at the right index.  Instead, you need the following change:

   for( int i=0; i < used(); i++ ) {
-    buf_clear( m_buf, i );
+    buf_clear( m_buf, (m_ri + i) % m_size );
   // ...

In 2.3, there was another indexing bug related to resize, see http://forums.accellera.org/topic/1443-/.


Hope that helps,


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.

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