Lock is a base object for all kinds of locks made by a program. All locks that are made by program are registered and almost always will be unlocked at program's end. Handled circumstances include return from main(), doing exit() (but not _exit()!), aborting due to signal (except for SIGKILL(#9) and severe memory damage).
Application specific definition of the Lock-inherited objects is deriving new object type from Lock (see FileLock for example) and redefining constructor and destructor so that the first provides suitable lock technique and the last - unlock technique.
Lock as transaction brackets lives while Lock-inherited object exists. If some lock must exist only inside some (exception free!) program scope, it can be made as an automatic object. If one need lock with inter-function behavior, one must create instance of lock object in dynamic memory.