|
Boost Users : |
From: Igor R. (igor_rubinov_at_[hidden])
Date: 2008-05-21 03:51:30
Hi,
Please, read the shared_mutex reference:
http://www.boost.org/doc/libs/1_35_0/doc/html/thread/synchronization.html#thread.synchronization.mutex_types.shared_mutex
as well as lock reference:
http://www.boost.org/doc/libs/1_35_0/doc/html/thread/synchronization.html#thread.synchronization.locks
Ususally you lock the mutex like this:
{ // the scope you wish to protect
scoped_lock(mutextObject); // - to make exclusive lock or shared_lock(mutextObject) to make shared lock
/// do your stuff here... }However, it was already discussed here that such a container will NOT be safe, because adding an element to std::vector might cause moving of all its elements, so the reference previously returned by at() won't be valid.
However, if you really do not need to remove elements from this container, then using std::deque instead of std::vector would solve this problem.
> template <typename T>
> void EntityUpdateBuffer<T>::push_back( const T& value )
> {
> // how to acquire a write lock?
>
> m_buffer.push_back(value);
> }
>
> template <typename T>
> const T& EntityUpdateBuffer<T>::at( int index ) const
> {
> // how to acquire read lock?
>
> return m_buffer.at(index);
> }
_________________________________________________________________
Explore the seven wonders of the world
http://search.msn.com/results.aspx?q=7+wonders+world&mkt=en-US&form=QBRE
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net