2-42 IBM Informix OnLine Database Server Administrator’s Guide
Managing Shared-Memory Resources
If an OnLine user process requires a specific latch, how does it determine if
the latch is available? The user process has two options:
Test for the latch; if unavailable, do not wait (that is, do not block).
Test for the latch; if unavailable, wait (that is, block).
Test-and-Set Institutions
Mostmachines use a single test-and-set instruction as part of the test that each
user process performs in its attempt to acquire a shared-memory latch. Test-
and-set, or TAS, prevents confusion between two user processes in a
multiuser environment. WithoutTAS , a user process could be interrupted
betweenthe test of the latch (to see if it is available) and the setting of the latch
(tomake it unavailable to other user processes). The interrupt could create a
situationin which more than one user process received “exclusive” access to
a resource.
To see how this confusion could occur, consider the following scenario.
ServerProcess A needs to acquire latch 201. Process A performs a test for the
latch and receives a positive response; the latch is available. Then the
processing time period for Process A ends. Process B begins executing.
Process B also needs latch 201. Process B performs a test for the latch and
receivesa positive response since the latch is still available. Process B sets the
latchand continues processing. Process B is interrupted (that is, its timeslice
expired) before it is ready to release the latch. When Process A continues
executing,it incorrectly assumes that it can claim latch 201. The test-and-set
instruction performs the latch test and sets the latch as a single, uninter-
ruptable event, eliminating confusion among processes.
Spin and Test Again
Whenan OnLine user process attempts to acquire a latch, it tests the latch for
availability. If the latch is not available, the user process can either block or
notblock. A third option is available on some multiprocessor UNIX operating
systems: spin and test again. The benefit of spinning instead of blocking is
that a user process can test for latch availability multiple times without the
overhead cost of putting the user process to sleep and later waking it. The
configuration parameter SPINCNT specifies the number of times that a user
processcan spin and test without actually going to sleep. (Refer to page 5-24
for information about tuning this parameter to improve performance.)