Boost logo

Boost :

From: Michael Caisse (boost_at_[hidden])
Date: 2007-07-20 18:12:55


Phillip Hellewell wrote:
> However, even the simplest _assignable_ class seems almost impossible to me
> to make thread-safe. You can synchronize operator= using both its own
> mutex(es) and rhs's mutex(es), which seems to solve the problem. But how do
> you prevent deadlock from something like this?
>
> Thread 1: x = y
> Thread 2: y = x
>
One common method is to perform the locks based on ordering of the mutex's
memory address. That way all threads are locking and releasing in the same order.

Michael

-- 
----------------------------------
Michael Caisse
Object Modeling Designs
www.objectmodelingdesigns.com

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