
Selçuk Giray Özdamar wrote:
const T& at(int index) const;
This doesn't look good.
T& at(int index);
Or this.
private: std::vector<T> m_buffer; boost::shared_mutex rw_mutex; };
template <typename T> const T& EntityUpdateBuffer<T>::at( int index ) const { // acquire lock read_lock lock(rw_mutex); return m_buffer.at(index); }
The problem with this code is that you are returning a reference to data that might be immediately invalidated. A push_back via another thread can cause the referenced memory to no longer be valid.
template <typename T> T& EntityUpdateBuffer<T>::at( int index ) { // acquire lock read_lock lock(rw_mutex); return m_buffer.at(index); }
Same problem. KevinH -- Kevin Heifner heifner @ ociweb.com http://heifner.blogspot.com Object Computing, Inc. (OCI) www.ociweb.com