A space location lock puts a logical lock on any single byte of
storage. The lock does not change the storage or effect your application's
access to the storage. The lock is a piece of information recorded
by the system.
Space location locks provide cooperative locking
similar to that provided by mutual exclusion (mutexes). However, space location
locks differ from mutexes in several respects:
- You can use the space location lock directly on the data it is protecting.
The space location lock does not require your application to create and maintain
an additional object. Correct results in your application still depend on
the fact that all threads that are accessing the data use the space location
lock.
- Space location locks allow an application to coordinate the use of different
locking request types. For example, more than one thread can use space location
locks to acquire a shared lock on the same data.
- Due to the extra lock types that are provided by space location locks,
the concept of an owner is slightly different than with mutexes. There can
be multiple owners of a shared lock if each owner has successfully acquired
the shared lock. For a thread to get an exclusive lock, all of the shared
locks must be unlocked.
- Space location locks have different performance implications to your application
than mutexes. A space location lock costs about 500 reduced instruction set
computer (RISC) instructions to lock in a path without contention between
other threads. A mutex costs about 50 RISC instructions in the same path.
However, a space location lock has no creation or deletion costs associated
with it, while a mutex costs approximately 1000 RISC instructions for creation
or deletion.
Note: Java™ does not have the ability to directly
use space location locks. Space location locks require the use of pointers.