Op Code (Hex) | Operand 1 | Operand 2 | Operand 3 | |
---|---|---|---|---|
03D3 | Mutex | Lock request template | Result |
Operand 2: Space pointer.
Operand 3: Signed binary(4) variable scalar.
Bound program access |
---|
|
Note: The term "mutex" in this instruction refers to a "pointer-based mutex".
The mutex, whose address is contained in operand 1, is allocated exclusively to the issuing thread. Mutual exclusion is achieved between the thread with the allocated mutex lock and all other threads attempting to acquire the same mutex lock. If the mutex lock is successful, LOCKMTX returns with the issuing thread as its holder.
The mutex must have been previously created by the CRTMTX instruction or be a copy of a mutex that was previously created by the CRTMTX instruction prior to attempting to lock the mutex. See the CRTMTX instruction for additional information regarding mutex copies.
The lock request template whose address is passed in operand 2 is used to determine if and for how long the issuer will wait for the mutex to become available in the event the mutex is already locked. The lock options are used to place the issuer into the mutex wait state. If an invalid option is specified, an EINVAL error number is returned. If operand 2 in a bound program is a null pointer value, the default lock request template is used (the binary 0 value is the default action). Operand 2 in non-bound programs must be a pointer to a lock request template. The pointer does not exist (hex 2401) exception is signaled if a null pointer value is used for operand 2 in a non-bound program. If the mutex lock can be immediately allocated to the issuer, then the lock request template is ignored.
Result is used to indicate the success or failure of the LOCKMTX instruction. If the mutex is locked by this instruction, then result is set to 0. If an error occurs, then the result is set to an error condition.
Mutexes can have either non-recursive or recursive behavior, which is specified at the time of creation. See the CRTMTX instruction for more information on mutex creation. A non-recursive mutex can only be locked once by a thread. Additional attempts to lock the same non-recursive mutex by a thread, will cause the EDEADLK error number to be returned. If a mutex was created as a recursive mutex then LOCKMTX can be used to recursively lock the mutex. The machine keeps track of the number of recursive locks for the mutex and requires that the thread use the Unlock Pointer-Based Mutex (UNLKMTX) instruction the same number of times to unlock the mutex before the mutex can be locked by a different thread. The maximum number of recursive locks is 32,767. The ERECURSE error number is returned if the maximum number of recursive locks is exceeded.
The mutex must be aligned on a 16-byte boundary.
The format of the lock request template follows:
Offset | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Dec | Hex |
| Field Name |
| Data Type and Length | ||||||||||||
0 | 0 |
| Time-out option |
| Char(1) | ||||||||||||
1 | 1 |
| Lock options |
| Char(1) | ||||||||||||
1 | 1 |
| Reserved (must be 0) |
| Bit 0 | ||||||||||||
1 | 1 |
| Wait time-out format |
| Bit 1 | ||||||||||||
|
|
|
| ||||||||||||||
1 | 1 |
| MPL (multiprogramming level) control during wait |
| Bit 2 | ||||||||||||
|
|
|
| ||||||||||||||
1 | 1 |
| Asynchronous signals processing option |
| Bit 3 | ||||||||||||
|
|
|
| ||||||||||||||
1 | 1 |
| Wait type |
| Bit 4 | ||||||||||||
|
|
|
| ||||||||||||||
1 | 1 |
| Reserved (binary 0) |
| Bits 5-7 | ||||||||||||
2 | 2 |
| Reserved (binary 0) |
| Char(6) | ||||||||||||
8 | 8 |
| Wait time-out value |
| Char(8) | ||||||||||||
8 | 8 |
| Seconds |
| Bin(4) | ||||||||||||
12 | C |
| Microseconds |
| Bin(4) | ||||||||||||
16 | 10 |
| --- End --- |
|
|
The time-out option describes the action taken when LOCKMTX cannot allocate the mutex to the issuer immediately.
Hex 00 = | Wait indefinitely for the mutex. |
Hex 01 = | Wait for the mutex for the specified amount of time. If the mutex still cannot be obtained, the EAGAIN error number is returned. |
Hex 02 = | Return immediately with an EBUSY error number. |
All other values for time-out option are reserved.
The lock options describes the action taken when LOCKMTX causes the issuer to be put into a mutex wait state.
The wait time-out format option determines the format of the wait time-out value. If the wait time-out format is specified as 0, then the wait time-out value consists of two 4-byte fields, specifying the number of seconds and the number of microseconds to wait for the mutex if it cannot be locked immediately. If the wait time-out format is specified as 1, then the wait time-out value consists of a single 8-byte field. See Standard Time Format for additional information on the format of the wait time-out value if wait time-out format is specified as 1. This field is only applicable if the time-out option is set to hex 01. If the time-out option is not set to hex 01, this field is ignored.
The MPL control during wait option controls whether the thread is removed from the current MPL (multiprogramming level) set or remains in the current MPL set when the thread enters a mutex wait. When entering a mutex wait state, the thread will normally remain in the current MPL set for an implementation-defined period which will not exceed 2 seconds. If the mutex wait has not been satisfied by the end of this period, the thread is automatically removed from the current MPL set. The automatic removal does not change or affect the total wait time specified on the LOCKMTX instruction. If the MPL control during wait option specifies do not remain in current MPL set (value of 1), then the thread will leave the MPL set immediately.
The asynchronous signals processing option controls the action to be taken if an asynchronous signal is pending or received while in a mutex 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 signal processing during mutex wait, the mutex wait is terminated and the result set to EINTR. Otherwise, when the asynchronous signals processing option indicates do not allow asynchronous signal processing during mutex wait, the thread remains in the wait until the mutex is allocated exclusively to the thread or until the wait time-out value expires.
The wait type option is used by kernel-mode programs or procedures to specify what type of wait to perform. The wait type field is ignored when the thread execution mode is not kernel-mode.
The wait time-out value establishes the maximum amount of time that the issuer waits for the requested mutex when the mutex lock cannot be immediately obtained and the time-out option is set to wait for a specified period of time (hex 01). The format of this field differs depending on which value is specified by the wait time-out format. If the wait time-out format is 0, then the wait time-out value consists of two 4-byte values, specifying the number of seconds and the number of microseconds to wait for the mutex. If the wait time-out format is 1, then the wait time-out value is a 64-bit unsigned binary value.> See Standard Time Format for additional information on the format of the wait time-out value if wait time-out format is specified as 1. If the wait time-out value is binary 0, then the process default wait time-out value is used. This field is only applicable if the time-out option is set to hex 01. If the time-out option is not set to hex 01, this field is ignored.
If a mutex is destroyed while another thread has a pending request to lock the mutex, an EDESTROYED error number is returned to the waiting thread. The ETYPE error number is returned if the mutex operand references a synchronization object that is not a pointer-based mutex.
The keep valid option on the Create Mutex (CRTMTX) instruction specifies whether the mutex is to remain valid when a thread is terminated while holding the lock on the mutex. The keep valid option must be set to hex 01 if a mutex should be remain valid after thread termination. The mutex is considered to be in a pending state when it is kept valid after thread termination. The next thread to lock a pending mutex will revalidate the mutex, but will receive an EUNKNOWN error number to indicate that the resource protected by this mutex may need special handling. Appropriate action is left up to the MI user's discretion. Specifying hex 00 for the keep valid option will result in the locked mutex being destroyed during thread termination. Threads waiting on the destroyed mutex will receive an EOWNERTERM error number.
If the space where a mutex resides is destroyed or corrupted, the system may detect this condition and attempt to clean up the mutex resource. This cleanup action will cause any thread waiting on the mutex to awaken with a return value of EINVAL.
The result is set to one of the following:
EAGAIN | 3406 - Operation would have caused the process to be suspended. |
EBUSY | 3029 - Resource busy. |
ECANCEL | 3456 - Operation canceled. |
EDEADLK | 3459 - Resource deadlock avoided. |
EDESTROYED | 3463 - The synchronization object was destroyed, or the object no longer exists. |
EINTR | 3407 - Interrupted function call. |
EINVAL | 3021 - The value specified for the argument is not correct. |
EOWNERTERM | 3462 - The synchronization object no longer exists because the owner is no longer running. |
ERECURSE | 3419 - Recursive attempt rejected. |
| Recursion limit exceeded for a recursive mutex. |
ETERM | 3464 - Operation terminated. |
ETYPE | 3493 - Object type mismatch. |
| A synchronization object at this address is not a pointer-based mutex. |
EUNKNOWN | 3474 - Unknown system state. |
| Owner of mutex was previously terminated leaving the mutex in a pending state. EUNKNOWN is returned to the first locker following this scenario. See CRTMTX for additional information. |
06 Addressing
08 Argument/Parameter
10 Damage Encountered
1C Machine-Dependent
20 Machine Support
22 Object Access
24 Pointer Specification
2E Resource Control Limit
36 Space Management
44 Protection Violation