Example: Passing an UCB address between asynchronously running programs

A program dynamically allocates a device. Once the device is successfully allocated, it is not eligible for deletion. After the device is allocated, the program finds the UCB associated with the device. Because the program has allocated the device, there is no need to pin it.

However, if the program passes the address to another program or unit of work, the passing program must pin the UCB. Then the passing program can pass the UCB address and the pin token to another unit of work (such as a task) for its use. For example, a program stores the UCB address in a commonly addressable storage location and posts another task. Before issuing the POST macro, the program must pin the UCB with the UCBPIN macro and specify the LASTING parameter, and then pass the UCB address and pin token to the task. The task must then unpin the UCB after it has finished using the UCB.

Note: If you do not issue UCBPIN with LASTING prior to the POST, the following can occur:
  1. The first program places the UCB address in a commonly addressable storage location and issues the POST macro without preceding it with a UCBPIN LASTING.
  2. The program terminates after issuing the POST macro. The system frees the pin at task or address space termination because you did not specify LASTING on UCBPIN. The device whose UCB address the program passed is deallocated. (Assume that there are no other outstanding allocations against the device).
  3. Before the posted work unit begins execution, the installation varies the device offline and then activates a new I/O configuration definition that does not include the device.
  4. After the activation, the posted program begins execution and obtains the passed UCB address and attempts to reference it. In this instance, the posted task references invalid storage because the UCB is deleted after the device is deleted.

If the UCB had been pinned with UCBPIN LASTING by the first program before the POST macro was issued, the device could not have been deleted when the first program unallocated the device.