Boost logo

Boost :

From: Kevlin Henney (Kevlin.Henney_at_[hidden])
Date: 2000-01-07 02:33:33


>> mutexed(const mutexed& from) :
>> lock(0),
>> value()
>> {
>> from.lock.acquire_lock();
>> this->value = from.value;
>> from.lock.release_lock();
>> // or, use constructor locking, if you want locks released on
exceptions
>> }
>
>This should use member initialisation, not assignment, ie
>
> mutexed(const mutexed& from)
> : lock(0), value((from.acquire_lock(), from.value))
> {
> from.release_lock();
> }

On rereading this, I realise that it's not exception safe. Here's the fix:

     mutexed(const mutexed& from)
       : lock(0), value((lock_acquirer(from.lock), from.value))
     {
     }

Kevlin


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