Boost logo

Boost :

From: Phillip Hellewell (sshock_at_[hidden])
Date: 2007-07-20 19:22:12


On 7/20/07, Peter Dimov <pdimov_at_[hidden]> wrote:
>
> The classic solution is to lock the mutexes in ascending order of their
> addresses, but I prefer
>
> X& X::operator=( X const& rhs )
> {
> X tmp( rhs ); // temporarily locks rhs.mutex
>
> scoped_lock lock( this->mutex );
> swap( tmp ); // or move_from( tmp )
>
> return *this;
> }
>
> It's always a good idea to only lock one mutex at a time if you can afford
> it.
>

Very nice! Thanks Michael and Peter. I especially liked your last
solution. I guess that shows how an efficient swap function can really come
in handy.

Phillip


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