Use for questions regarding the mechanism to prevent concurrent access to shared resources by means of lock files or in-memory synchronization primitives. For the mechanism to prevent access to unattended desktop computers, use "screen-lock" instead. For questions regarding the unresponsive computer programs, use "freeze" instead.
Overview
In multi-tasking operating systems, it is often necessary to prevent concurrent access to a single resource available to multiple threads. Common cases of such resources are e.g. files or shared memory segments, where two processes writing simultaneously to the resource may corrupt each other's data, or a process reading from the resource may receive inconsistent data if another process is writing to the resource at the same time.
Examples
-
A file whose presence indicates to other processes that a certain resource is in use and therefore locked. A process wanting to access the resource checks for the presence of the lock file, and if it is found, refrains from using the resource (at least until the file has disappeared). If the file is not present, the process will create the file and start using the resource.
If the process is abnormally terminated before it can remove the files, a stale lock condition occurs in which no process is able to use the resource anymore until the file is removed by external intervention.
Lock files may be created e.g. by using the
lockfile
command included in theprocmail
package. -
A variable or data structure indicating to other threads that a resource is locked. Many Unix-like operating systems include the
pthreads
library, which contains an implementation of Mutexes and other locking and synchronization devices, along with function calls to manage them.
Related tags
Further reading
Misplaced uses
This tag should not be used for
- the mechanisms that lock the screen of desktop computers to prevent unauthorized access when the computer is unattended. Use the screen-lock tag for such questions.
- conditions in which a computer program is "locked up", i.e. unresponsive. Use either freeze or hang in that case.