Creating Libraries

A library program is created by using the EXPORT declaration to declare procedures to be exported as entry points, and by using the FREEZE statement. The duration of a library program following initiation is controlled by the TEMPORARY or PERMANENT specification of the FREEZE statement. The allowed sharing of a library program is controlled by the SHARING compiler control option.

Users of a library can be restricted through the normal file access features provided by the system. The allowed simultaneous usage of a library can be specified by the creator of the library at compilation time through the SHARING compiler control option. The library sharing can be PRIVATE, SHAREDBYALL, SHAREDBYRUNUNIT, or DONTCARE.

PRIVATE

A separate instance of the library is started for each invocation of the library. Any changes made to global items in the library by the program unit (block, procedure, or external task) invoking the library apply only to that particular calling program.

SHAREDBYALL

All invocations of the library share the same instance of the library. Any changes made to global items in the library by a program unit that has invoked the library apply to all users of that library.

SHAREDBYRUNUNIT

A run unit consists of a program, all SHAREDBYRUNUNIT libraries it initiates directly, and any SHAREDBYRUNUNIT libraries initiated when code from another frozen library runs on the stack of the program.

Note that a library is its own run unit until it freezes. For example, program P initiates library A and, before library A freezes, it in turn initiates library B. Now library B is in library A run unit, not in program P run unit. Had library A initiated library B after freezing, both library A and library B would be in program P run unit.

DONTCARE

The operating system determines the sharing. This determination is unknown to all users invoking the library. The default value of the SHARING compiler control option is DONTCARE.