This simple class allows the locking of a class-wide, object-wide or system-wide mutex for the duration of a code block. The C++ scoping rules for the calling of the destructor at the end of the block in which such an autolock object is constructed. The nice thing about wrapping a mutex with an autolock is that you don't have to worry about all those intermediate returns in your code any more. The autolocks object will always be called, and your mutex is released.