ENQ and DEQ conditional and unconditional requests

Up to this point, only unconditional requests have been considered. You can, however, make conditional requests by using the COND parameter on ISGENQ and the RET parameter on the ENQ and DEQ macros. One reason for making a conditional request is to avoid the abnormal termination that occurs if you issue two ENQ macros for the same resource within the same task or when a DEQ macro is issued for a resource for which you do not have control.

See ISGENQ conditional and unconditional requests for detailed information on conditional requests for ISGENQ.

The RET parameter of ENQ provides the following options:
RET=TEST
Indicates the availability of the resource is to be tested, but control of the resource is not requested.
RET=USE
Indicates control of the resource is to be assigned to the active task only if the resource is immediately available. If any of the resources are not available, the active task is not placed in a wait condition.
RET=CHNG
Indicates the status of the resource specified is changed from shared to exclusive control.
RET=HAVE
Indicates that control of the resource is requested conditionally; that is, control is requested only if the same task does not already have control of or an outstanding request for the same resource.

For the following descriptions, the term “active task” means the task issuing the ENQ macro. No reference is intended to other tasks that might be active in other processors of a multiprocessor.

Use RET=TEST to test the status of the corresponding qname, rname, and scope combination, without changing the list in any way or waiting for the resource. RET=TEST is most useful for determining if the task already has control of the resource. It is less useful for determining the status of the list and taking action based on that status. In the interval between the time the control program checks the status and the time your program checks the return code and issues another ENQ macro, another task could have been made active, and the status of the list could have changed.

Use RET=USE if you want your task to receive control of the resource only if the resource is immediately available. If the resource is not immediately available, no entry will be made on the list and the task will not be made to wait. RET=USE is most useful when there is other processing that can be done without using the resource. For example, by issuing a preliminary ENQ with RET=USE in an interactive task, you can attempt to gain control of a needed resource without locking your terminal session. If the resource is not available, you can do other work rather than enter a long wait for the resource.

Use RET=CHNG to change a previous request from shared to exclusive control.

Use RET=HAVE to specify a conditional request for control of a resource when you do not know whether you have already requested control of that resource. If the resource is owned by another task, you will be put in a wait condition until the resource becomes available.

The RET=HAVE parameter on DEQ allows you to release control and prevents the control program from abnormally ending the active task if a DEQ attempts to release a resource not held. If ENQ and DEQ are used in an asynchronous exit routine, code RET=HAVE to avoid possible abnormal termination.