This is one of the things I do like about C++: { Lock lock(resource); // constructor does the locking, // destructor does the unlocking if (! lock.ok()) return false; if (! foo()) return false; if (! bar()) return false; return true; } And the unlocking happens automatically whenever the lock goes out of scope. b.