The linked post below explains locks in full length. However, the question you should ask yourself is do you really need one?
Also a little further down in the linked thread: tl;dr, don’t use locks unless you really know what you are doing, and even then don’t use them. There is almost always a better way.