I have a question concerning the use of boost::lock_guard (or similar scoped locks) and using variables that should be protected by the lock in a return>
Just a straight return as in your first example is correct. The return value is constructed before the local variables are destroyed, and thus before the lock is released.