Jump to content

Recommended Posts

Hi All,

I'm new at this forum. 

I encounter problem with circular_buffer.

Let me explain it on simple example (code is from circular_buffer.h):

 

 

I have a circular_buffer with few elements .

After read one of them element is destroyed:

 

template < typename T >
T
circular_buffer<T>::read()
{
  T t = read_data();

  buf_clear( m_buf, m_ri );
  increment_read_pos();

  return t;
}

 

template < typename T >
inline void
circular_buffer<T>::buf_clear( void* buf, int n )
    { (static_cast<T*>(buf) + n)->~T(); }
 
} // namespace tlm
 

... but

 

In dectructor  all elements are destroyed ... again

 

template < typename T >
circular_buffer<T>::~circular_buffer()
{
  for( int i=0; i < used(); i++ ) {
    buf_clear( m_buf, i ); //!!!!
  }
  buf_free( m_buf );
}
 

 

 

This case GPF's randomly.

I notice that when I change desctructor code 

to 

 

for( int i=m_ri; i < used() % m_size; i++ ) {

 

problem disappears

 

I'm using SystemC 2.3.0 Is this a bug in TLM sources or I'm doing something wrong ?

 

Radek

Share this post


Link to post
Share on other sites

AFAICS, this is another symptom of a known issue and fixed in 2.3.1. You should upgrade.

Quoting the RELEASENOTES:
 

  •  The implementation-defined tlm::circular_buffer class has been updated with the following changes
    •     now provides a "clear()" member function to drop the current contents,
    •     fix a segmentation fault due to freeing invalid memory in "resize()", which could happen in some cases,
    •     work around a parsing error on some EDG-based C++ frontends.

 

 

Greetings from Duisburg,
  Philipp

Share this post


Link to post
Share on other sites

Oh, there seems to be still an issue in 2.3.1, you should change the circular_buffer::clear function to

template < typename T >
void
circular_buffer<T>::clear()
{
  for( int i=0; i < used(); i++ ) {
    // buf_clear( m_buf, i ); // << BUG HERE
    buf_clear( m_buf, (m_ri + i) % m_size ); // This should(tm) be correct
  }
  m_free = m_size;
  m_used = m_ri = m_wi = 0;
}

Thanks for reporting. I'll take this to the Language Working Group to make sure a fix will be included in the next release of the proof-of-concept simulator.

(I would still recommend to upgrade to 2.3.1... ;) )

Greetings from Duisburg,
  Philipp

Share this post


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