On the first call on an entry point of a library or at an explicit linkage request, the calling program is suspended. The description of the entry point in the library template of the calling program is compared to the description of the entry point with the same name in the library directory associated with the referenced library.
If the entry point does not exist in the library, or if the two entry point descriptions are not compatible, a run-time error is given and the calling program is terminated. If the entry point exists and the two entry point descriptions are compatible, the operating system automatically initiates the library program (if it has not already been initiated). The library program runs normally until it executes a FREEZE statement, which makes the entry points available. All of the entry points of the library that are declared in the calling program are linked to the calling program, and the calling program resumes execution.
If a calling program declares an entry point that does not exist in the library, no error is generated when the library is initiated; however, a subsequent call on that entry point causes a MISSING ENTRY POINT run-time error, and the calling program is terminated.
A library can be specified to be permanent or temporary. A permanent library remains available until it is terminated either by the Operator Display Terminal (ODT) commands DS (Discontinue) or THAW, or by execution of a CANCEL statement. A temporary library remains available as long as users of the library remain. A temporary library that is no longer in use unfreezes and resumes running as a regular program.
The PERMANENT or TEMPORARY specifications of the FREEZE statement control the duration of a library. Any running program that executes a FREEZE statement becomes a library. When a library is initiated by explicitly running the library program instead of by calling an entry point, the FREEZE statement should specify PERMANENT. If TEMPORARY is specified, the library immediately unfreezes because it has no users. After a library unfreezes, it must not execute another FREEZE statement in an attempt to become a library again.
The CONTROL specification of the FREEZE statement controls the nature of the freeze. The program is set up as a permanent library, but after the freeze operation has been performed, control is transferred to the specified procedure, known as the control procedure. The control procedure must be untyped and must have no parameters.
Once the control procedure is in control, the library can keep track of the number of its users through the task attribute LIBRARYUSERS. The library can unfreeze itself by changing the task attribute STATUS to VALUE(GOINGAWAY). After this change, the library is equivalent to a thawing library. When the control procedure is exited, the library unfreezes if there are no users. If there are users, the library becomes an ordinary library, and a warning message is issued.
Because a library program initially runs as a regular program, the flow of execution can be such that the execution of a FREEZE statement is conditional and can occur in any block that contains an EXPORT list.
If a calling program causes a library program to be initiated and the library program terminates without executing a FREEZE statement (for example, because it was not actually a library program and, thus, had no FREEZE statement), the attempted linkage to the library entry points cannot be made, and the calling program is terminated.
Linkage to a library can be requested explicitly by using the LINKLIBRARY function. For more information, see LINKLIBRARY Function.

