From: Jason Stewart (jstewart_at_[hidden])
Date: 2005-07-29 12:00:48


Try

void foo()
{
        shared_ptr<scoped_lock> lk;
        if (condition)
                lk.reset(new scoped_lock(mutex));

        do something
}

The smart pointer will automatically unlock when it goes out of scope.