To use the latch manager, your application should call the latch
manager services in the following sequence:
- Create a latch set. Your application begins
by calling the Latch_Create service to create a set of latches in
the current primary address space. Each latch can then be used to
serialize resources. Your application can assign latches to resources
in whatever way it desires.
- Provide latch identities for latches. You
might choose to use the latch identity service (ISGLID/ISGLID64) to
create latch identities and other attributes for your latches. Latches
whose attributes are not changed by the usage of the obtainer can
be created right after the latch set is created. Latches whose
attributes are changed by usage of obtainer can still be initialized
to a "not in use state" right after the latch set is created. The
attributes of latches changed by obtainers should be updated or replaced
by ISGLID/ISGLID64 before and after usage with appropriate values.
- Request ownership of latches. Programs that
run as part of your application can call the Latch_Obtain service
to request exclusive or shared ownership of latches associated with
required resources. If there is no contention for a latch at the time
of the Latch_Obtain request, the latch manager can grant ownership
of the latch immediately. The caller of Latch_Obtain specifies a
parameter that tells the latch manager what to do when a latch is
not immediately available, which is one of the following:
- Queue the request and suspend the requestor until the latch manager
eventually grants ownership of the latch to the requestor
- Do not queue the request; return control to the requestor
- Queue the request, return control to the requestor, then post
an event control block (ECB) when the latch manager grants ownership
of the latch to the requestor.
When a requestor obtains ownership of a latch, the requestor
can read or modify the associated resource, depending on the type
of ownership that was requested (shared or exclusive).
- Release ownership of owned latches or pending
latch requests. After a requestor finishes using the resource,
it calls the Latch_Release service to release the latch so other requestors
can use the resource. Requestors can also call Latch_Release to release
a pending request to obtain ownership of a latch that has been queued
by the latch manager.
- If an error occurs, purge all owned latches and
pending requests for a particular requestor. Latch_Purge, which
is similar to Latch_Release, is a convenient way to purge all granted
and pending requests for a specific requestor within a specific latch
set. The latch manager provides the Latch_Purge service for use by
an application's termination resource manager.
Planning to use the latch manager callable services describes how to set up your application to
use the latch manager callable services.