Data management considerations for multithreaded programming

When you manage data in a multithreaded program, be aware of these considerations.

  • File open operations

    Only integrated file system stream files, printer files, distributed data management (DDM) files of type *IP, and local database files can be opened in a multithread-capable job. Attempts to open *FILE objects other than print files, type *IP DDM files, or local database files cause a CPF4380 escape message to be sent to the function that opens the file. The CPF4380 escape message signals that open attributes are not valid in a multithreaded process. Local database files include physical and logical files. Loosely coupled parallel (LCP) files are not local and send the CPF4380 escape message when a function tries to open the file. Local database files also do not include save files (*SAVF), which are device files, or other communications files. You cannot open a printer file by specifying SPOOL(*NO). If you specify SPOOL(*NO) when trying to open the print file, the CPF4380 escape message is sent to the function that tried to open the print file.

    Multithread-capable jobs allow shared opens. However, an open data path (ODP) cannot be shared between threads. If a file is opened SHARE(*YES) and OPNSCOPE(*ACTGRPDFN) is specified, any subsequent shared open within the same thread that is running in the same activation group can share the ODP. If a file is opened SHARE(*YES) with OPNSCOPE(*JOB) specified, any subsequent shared open of the file within the same thread can share the ODP.

  • File overrides

    Multithreaded applications can only issue overrides in their initial thread. Any attempt to issue an override in a secondary thread returns the CPF180C escape message. Only overrides with job-level and activation group-level scope affect secondary threads; overrides of call-level scope are not visible. Overrides of all scope levels can affect initial threads. You can use three different types of file override commands: Override with Database File (OVRDBF), Override with Printer File (OVRPRTF), and Override with Message File (OVRMSGF).

    You can delete overrides in the initial thread, but not in secondary threads, by calling the Delete Override (DLTOVR) command. DLTOVR returns the CPF180C escape message if thrown against a secondary thread.

  • Reclaim resources commands

    None of the commands that reclaim resources are threadsafe because the IBM® i operating system does not track resources. The operating system cannot identify which resources are in use by which threads. You cannot call the Reclaim Resources (RCLRSC) and Reclaim Activation Group (RCLACTGRP) commands in secondary threads. RCLRSC and RCLACTGRP can be called in the initial thread of a multithread-capable job (ALWMLTTHD(*YES)) if secondary user threads are not present. If secondary user threads are present in the job, these commands send a CPF180B escape message to the caller of the command.