
29 Jul
2005
29 Jul
'05
5 p.m.
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.