A lock is a device for raising and lowering boats between stretches of water of different levels on river and canal waterways.  The way it works is very simple.  It consists of a chamber with a water-tight gate at either end. 

The principle of operating a lock is simple. For instance, if a boat travelling downstream finds the lock already full of water: