A lock is a mechanism implemented in software with some special hardware support to ensure critical sections of concurrent code that are trying to access common data are executed by one thread at a time. Reading and writing should be handled differently. There are different types of lock including mutex locks, spinlocks, and blocking locks.
Terminology
A lock is either held by a thread or available. At most one thread can hold a lock at a time. A thread attempting to acquire a lock that is already held is forced to wait. How it waits is implementation dependent.
Locks will all generally include the following two methods:
Lock
Attempts to acquire the lock. If the lock is already held by another thread, the lock waits by a mechanism specified by the type of lock being used.
Unlock
Releases the lock, making it accessible to other threads attempting to acquire it.