Lock Object (LOCK)


Op Code (Hex) Operand 1


03F5 Lock request template


Operand 1: Space pointer.
Bound program access

Built-in number for LOCK is 46. LOCK ( lock_request_template : address )

Description

Locks for system objects identified by system pointers in the space identified by operand 1 are allocated to the requesting thread or its containing process or a transaction control structure. The lock state desired for each object is specified by a value associated with each system pointer in the lock request template (operand 1).

The lock request template must be aligned on a 16-byte boundary. The format is as follows:


Offset
Dec Hex
Field Name
Data Type and Length
0 0
Number of lock requests in template
Bin(4)
4 4
Offset to lock state selection values
Bin(2)
6 6
Wait time-out value for instruction
Char(8)
14 E
Lock request options
Char(2)
14 E
Lock request type
Bits 0-1



00 = Immediate request- If all locks cannot be immediately granted, signal lock request not grantable  (hex 1A02) exception.
01 = Synchronous request- Wait until all locks can be granted.
10 = Asynchronous request- Allow processing to continue and signal event when the object is available.


14 E
Access state modifications
Bits 2-3
14 E
When the thread is entering lock wait for synchronous request:
Bit 2



0 = Access state should not be modified.
1 = Access state should be modified.


14 E
When the thread is leaving lock wait:
Bit 3



0 = Access state should not be modified.
1 = Access state should be modified.


14 E
Reserved (binary 0)
Bits 4-5 +
14 E
Time-out option
Bit 6



0 = Wait for specified time, then signal time-out exception.
1 = Wait indefinitely.


14 E
Template extension specified
Bit 7



0 = Template extension is not specified.
1 = Template extension is specified.


14 E
Lock scope
Bit 8



0 = Lock is scoped to the lock scope object type.
1 = Lock is scoped to the current thread.


14 E
Lock scope object type
Bit 9



0 = Process containing the current thread.
1 = Transaction control structure attached to the current thread.


14 E Reserved Bit 10
14 E Reverse unlock option Bit 11
0 = Unlocks will be performed in template order.
1 = Unlocks will be performed in reverse template order.


14 E Reserved (binary 0) Bits 12-15
16 10
--- End ---

The lock object template extension is only present if template extension specified is indicated above. Otherwise, the object(s) to be locked should immediately follow.

Offset
Dec Hex
Field Name
Data Type and Length
0 0
Lock object template extension
Char(16)
0 0
Extension options
Char(1)
0 0
Modify thread event mask option
Bit 0



0 = Do not modify thread event mask
1 = Modify thread event mask


0 0
Reserved (binary 0)
Bits 1-7
1 1
Extension area
Char(15)
1 1
New thread event mask
UBin(2)
3 3
Previous thread event mask
UBin(2)
5 5
Reserved (binary 0)
Char(11)
16 10
Object(s) to be locked
[*] System pointer



This should be repeated as specified by number of lock requests in template above.


* *
--- End ---

The lock state selection is located by adding the offset to lock state selection values above to operand 1.

Offset
Dec Hex
Field Name
Data Type and Length
0 0
Lock state selection
[*] Char(1)



(repeated for each pointer in the template)


0 0
Requested lock state
Bits 0-4



(1 = lock requested, 0 = lock not requested) Only one state may be requested.


0 0
LSRD lock
Bit 0
0 0
LSRO lock
Bit 1
0 0
LSUP lock
Bit 2
0 0
LEAR lock
Bit 3
0 0
LENR lock
Bit 4
0 0
Reserved (binary 0)
Bits 5-6 +
0 0
Entry active indicator
Bit 7



0 = Entry not active - This entry is not used.
1 = Entry active - Obtain this lock.


* *
--- End ---

Note: Fields indicated with a plus sign (+) are ignored by the instruction.

Lock Allocation Procedure

A single Lock Object instruction can request the allocation of one or more lock states on one or more objects. Locks are allocated sequentially until all locks requested are allocated.

When two or more threads are competing for a conflicting lock allocation on a system object, the machine attempts to first satisfy the lock allocation request of the thread with the highest priority. Within that priority, the machine attempts to satisfy the request that has been waiting longest.

If any exception is identified during the instruction's execution, any locks already granted by the instruction are released, and the lock request is canceled.

For each system object lock, counts are kept by lock state and by thread, process, or transaction control structure. When a lock request is granted, the appropriate lock count(s) of each lock state specified is incremented by 1.

If a transfer of a lock from another thread causes a previously unsatisfied lock request to become satisfied, the lock request and the transfer lock are treated independently relative to lock accounting. The appropriate lock counts are incremented for both the lock request and the transfer lock function.

The offset to lock state selection values specifies an offset from the beginning of the lock request. This offset is used to locate the lock state selection values.

The wait time-out value for instruction field establishes the maximum amount of time that a thread competes for the requested set of locks when lock request type is either synchronous or asynchronous. When lock scope object type has a value of binary 1, the lock wait time interval value for the transaction control structure attached to the current thread is used to establish the maximum amount of time that the thread competes for the set of locks. See Standard Time Format for additional information on the format of the wait time-out value for instruction.

The maximum wait time-out interval allowed is a value equal to (248 - 1) microseconds. Any value that indicates more time than the maximum wait time-out causes the maximum wait time-out to be used. If the wait time-out field is specified with a value of binary 0, then the value associated with the default wait time-out field in the process definition template establishes the time interval.

When a requested lock state cannot be immediately granted, any locks already allocated by this Lock Object instruction are released, and the lock request type specified in the lock request template establishes the machine action. The lock request types are described in the following paragraphs.

When:

the access state modification field in the lock request template specifies whether the access state of the process access group is to be modified on entering and/or returning from the lock wait. The field has no effect if the process instruction wait access state control attribute specifies that no access state modification is allowed. If the process attribute value specifies that access state modification is allowed and the wait on event access state modification option specifies modify access state, the machine modifies the access state for the specified process access group.

If the thread requesting the locks belongs to a multi-threaded process, no access state modification is performed.

If the lock request type is synchronous and the invocation containing the lock instruction is terminated, then the lock request is canceled.

If an asynchronous lock request is satisfied, then the object locked event is signaled to the requesting thread. If the request is not satisfied in the time interval established by the wait time-out field specified in the lock request template, the asynchronous lock wait timeout event is signaled to the requesting thread. No locks are granted, and the lock request is canceled. If an object is destroyed while a thread has a pending request to lock the object, the object destroyed event is signaled to the waiting thread. These events are signaled to the requesting thread, regardless of the scope of the requested lock.

If the lock request type is asynchronous and the invocation containing the Lock Object instruction is terminated, then the lock request remains active.

The lock scope field and the lock scope object type field determines which scope all specified lock requests will be allocated to, either a thread, process or transaction control structure. When lock scope has a value of binary 0 and lock scope object type has a value of 0, the lock scope will be the process containing the current thread. When lock scope has a value of binary 0 and lock scope object type has a value of 1, the lock scope will be the transaction control structure that is attached to the current thread. If the current thread does not have a transaction control structure attached, then the lock scope will be the process containing the current thread. When lock scope has a value of binary 1 the lock scope will be to the current thread and the value of the lock scope object type will be used to determine how lock conflicts are detected. Locks scoped to a thread with a lock scope object type value of process containing the current thread can never conflict with a lock scoped to its containing process, but may conflict with a lock scoped to a different process, a transaction control structure, or any other thread (depending on the lock states involved). Locks scoped to a thread with a lock scope object type value of transaction control structure attached to the current thread can never conflict with a lock scoped to the transaction control structure, but may conflict with a lock scoped to a different transaction control structure, a process, or any other thread (depending on the lock states involved).

If lock scope object type has a value of transaction control structure attached to the current thread and the transaction control structure state does not allow objects to be locked on behalf of the transaction control structure, an object not eligible for operation  (hex 2204) exception is signaled.

Allocated process scope locks are released when the process terminates. Allocated thread scope locks are released when the thread terminates. If a thread requested a process scope lock, the process will continue to hold that lock after termination of the requesting thread. If a thread requested a transaction control structure scope lock, the transaction control structure will continue to hold that lock after the termination of the requesting thread.

If a thread is terminated while waiting for a lock with a lock request type of either synchronous or asynchronous, the lock request is canceled regardless of the scope of the requested lock.

The modify thread event mask option controls the state of the event mask in the thread executing this instruction. If the event mask is in the masked state, the machine does not schedule signaled event monitors in the thread. The event monitors continue to be signaled by the machine or other threads. When the thread is modified to the unmasked state, event handlers are scheduled to handle those events that occurred while the thread was masked and those events occurring while in the unmasked state. The number of events retained while the thread is masked is specified by the attributes of the event monitor associated with the thread.

A lock request with an asynchronous lock request type cannot have the modify thread event mask option set to binary 1.

If the system security level machine attribute is hex 40 or greater and the thread is running in user state, then the modify thread event mask option is not allowed and a template value invalid  (hex 3801) exception is signalled.

When the modify thread event mask is set to binary 1, the previous thread event mask will be returned and the new thread event mask will take effect only when the lock(s) have been successfully granted. If the lock request is not successful, the previous thread event mask value is not returned, nor does the new thread event mask take effect.

Whether masking or unmasking the current thread, the new mask takes effect upon completion of a satisfied lock object.

Valid masking values are:

0 Masked
256 Unmasked

Other values are reserved. If any other values are specified, a template value invalid  (hex 3801) exception is signaled.

The thread is automatically masked by the machine when event handlers are invoked. If the thread is unmasked in the event handler, other events can be handled if another enabled event monitor within that thread is signaled. If the thread is masked when it exits from the event handler, the machine explicitly unmasks the thread.

The asynchronous signals processing option controls the action to be taken if an asynchronous signal is pending or received while in Lock wait. If an asynchronous signal that is not blocked or ignored is generated for the thread and the asynchronous signals processing option indicates allow asynchronous signals processing during Lock wait, the Lock wait will be terminated and an asynchronous signal terminated MI wait  (hex 4C01) exception is signaled. Otherwise, when the asynchronous signals processing option indicates do not allow asynchronous signals processing during Lock wait, the thread remains in the wait until all requested locks can be granted or until the wait time-out value for instruction expires.

Authorization Required

Lock Enforcement

Exceptions

06 Addressing

08 Argument/Parameter

0A Authorization

10 Damage Encountered

1A Lock State

1C Machine-Dependent

20 Machine Support

22 Object Access

24 Pointer Specification

2E Resource Control Limit

36 Space Management

38 Template Specification

3A Wait Time-Out

44 Protection Violation

4C Signals Management