Locks come to the rescue when dealing with race conditions. For example, in order to fix the preceding example, all you need is a lock around the procedure. A lock is like a guardian that will allow only one thread to take hold of it (we say to acquire a lock), and until that thread releases the lock, no other thread can acquire it. They will have to sit and wait until the lock is available again.