In a server back end environment, you may have some objects which you share amongst several sessions. This means that they could be accessed on behalf of several clients all at once. You may want to prevent this happening by locking the object as the first client's request accesses it, and then unlocking it again as the request handler for that client no longer needs access to it.
You can create new Lock objects with the Lock() constructor.
It is good manners to unlock resources as soon as you can so that other processes can carry on running. You should not rely on the script exit handler unlocking the locks you place on objects.
Be careful when you use locks. It is possible to place mutually exclusive locks on objects and introduce a deadlocking situation. There is a potential for this if your script is locking more than one object and the locks are not correctly nested.
If you don't implement locks when necessary, you run the risk of run-time errors as your system can run out of resources.