Boost logo

Boost :

From: Phillip Hellewell (sshock_at_[hidden])
Date: 2007-07-20 16:38:09


On 7/20/07, Stefan Seefeld <seefeld_at_[hidden]> wrote:
>
> Michael Caisse wrote:
> > How about using boost::shared_ptr. Something like this in your class
> instead:
> >
> > boost::shared_ptr< boost::recursive_mutex > myMutex;
>
> Then you would protect both copies of the resource that is part of the
> class
> by a single (shared) mutex. That doesn't sound right.
>

Exactly, I don't want to copy or share the mutex in any way. I want each
object to have its own mutex.

I just wanted to avoid having to write copy ctor for no reason. But I just
realized that my whole argument is definitely moot. In all my classes with
mutexes that I want to be copyable, I need to write a copy ctor and
operator= anyways to make them thread-safe. For instance, I'll have a
function, say foo(), that initializes a shared pointer of some kind. This
function is already synchronized using scoped_lock(m_mutex). To be
thread-safe, I really need my copy ctor to be synchronized (with rhs.m_mutex)
and my operator= to be synchronized too (with both m_mutex and rhs.m_mutex).

Phillip


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk