MF 

Thread-Local-Storage Section

The Thread-Local-Storage Section describes data which is unique to each thread, and is persistent across calls. The VALUE clause can be used to provide initial values for this data. The syntax of data description entries is defined in the topic File Description Entry Skeleton.

Thread-local storage can be viewed as thread-specific working storage. This is useful for resolving contention problems in most reentrant programs. In many cases, a non file-handling program can be made completely reentrant by simply changing the WORKING-STORAGE SECTION header to a THREAD-LOCAL-STORAGE SECTION header.

Restriction: THREAD-LOCAL-STORAGE cannot be used in class programs compiled for JVM COBOL code (but can be used in procedural COBOL programs compiled to JVM COBOL code).

General Format



Syntax Rules

  1. The EXTERNAL clause is not allowed.
  2. For JVM COBOL applications, data items cannot be object references.

General Rules

  1. A separate copy of each data item in thread-local storage is created and set to its initial state for each new thread of execution that enters the program. The data item is only visible to the thread causing its execution. The data item is destroyed when the creating thread's execution terminates, or when a CANCEL statement on the program is executed; otherwise, on subsequent calls to the program within that thread, the data item is in its last used state.
  2. In a single-threaded environment, thread-local storage behaves exactly as working storage.