Multithreading
To use COBOL support for multithreading, you need to understand how processes, threads, run units, and program invocation instances relate to each other.
The operating system and multithreaded applications can handle execution flow within a process, which is the course of events when all or part of a program runs. Programs that run within a process can share resources. Processes can be manipulated. For example, they can have a high or low priority in terms of the amount of time that the system devotes to running the process.
Within a process, an application can initiate one or more threads, each of which is a stream of computer instructions that controls that thread. A multithreaded process begins with one stream of instructions (one thread) and can later create other instruction streams to perform tasks. These multiple threads can run concurrently. Within a thread, control is transferred between executing programs.
In a multithreaded environment, a COBOL run unit is
the portion of the process that includes threads that have actively
executing COBOL programs. The COBOL run unit continues until no COBOL
program is active in the execution stack for any of the threads. For
example, a called COBOL program contains a GOBACK
statement
and returns control to a C program. Within the run unit, COBOL programs
can call non-COBOL programs, and vice versa.
Within a thread, control is transferred between separate COBOL and non-COBOL programs. For example, a COBOL program can call another COBOL program or a C program. Each separately called program is a program invocation instance. Program invocation instances of a particular program can exist in multiple threads within a given process.
The following illustration shows these relationships between processes, threads, run units, and program invocation instances.
Language Environment® Programming Guide (Program management model,
Understanding the basics: threads)
Choosing THREAD to support multithreading
Transferring control to multithreaded programs
Ending multithreaded programs
Processing files with multithreading
Handling COBOL limitations with multithreading