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.
General Format
Syntax Rules
- The EXTERNAL clause is not allowed.
- For JVM COBOL applications, data items cannot be object references.
General Rules
- 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.
- In a single-threaded environment, thread-local storage behaves exactly as working storage.