Race condition: Difference between revisions

→‎Locks: - Added a few words concerning locking
No edit summary
(→‎Locks: - Added a few words concerning locking)
Line 51:
 
Various sorts of locking primitives include [[semaphore]]s and [[mutex]]es (mutual exclusion objects).
====Cooperative Locks====
Semaphores are commonly used to lock memory regions shared by processes. Semaphores are often called ''cooperative locks'' because processes must actively cooperate by acquiring and releasing the semaphore. Any process that ignores the semaphore can access the shared memory whether or not another process has acquired the semaphore.
====Enforced Locks====
Synchronization locks can be designed into threading architectures by encapsulating the locking and unlocking operations in accessor methods for shared memory regions. All access to the shared memory region then enforces the locking policy for all threads.
 
Languages with built-in threading syntax commonly provide very simple ways to enforce locks. Java provides the ''synchronized'' key word to designate a code block with enforced locking.
 
Ada provides ''protected objects'' with locking characteristics based upon the kind of access method described. A protected ''procedure'' enforces a write lock, allowing unconditional access to the object by only a single thread at a time. A protected ''entry'' enforces a write lock, allowing conditional access to the object by one thread at a time. A protected ''function'' provides a shared read lock, allowing multiple read access to the object at the same time. Many locking patterns[http://home.att.net/~jimmaureenrogers/Shared_Resource_Design_Patterns.html] can be defined using these three capabilities.
 
{{stub}}
Anonymous user