home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 14 Text
/
14-Text.zip
/
cobmthrd.zip
/
MLTITHRD.DOC
Wrap
Text File
|
1994-02-26
|
6KB
|
138 lines
Creating Multi-Threaded Applications with the Run Time Environment
(C) Copyright 1991 Micro Focus Ltd.
1. Creating A Multi-Threaded Application
-----------------------------------------
1.1 Contents
-------------
1. Creating A Multi-Threaded Application
1.1 Contents
1.2 Introduction
1.3 Installing The Support For Multi-Threaded Applications
1.4 Example Program
1.5 Thread Local Data And Shared Data
1.6 Creating A New Thread Of Execution
1.7 Thread Termination
1.8 Restrictions
1.2 Introduction
-----------------
This document describes the current facilities available in the Run
Time Environment to create multi-threaded COBOL applications
In a multi-threaded application, the user is able to set off several
concurrent paths of execution within the same program. Each of these paths
of execution is known as a "thread". On OS/2, this facility is mapped onto OS/2
threads. On DOS it is mapped onto the run-time's own pre-emptive task
switching which emulates the behavior of OS/2 threads. Generally, each thread will want to
have its own thread local data as well as having access to shared data that
is available to all threads.
1.3 Installing The Support For Multi-Threaded Applications
-----------------------------------------------------------
The Run Time Support to enable the creation of new threads of execution is
contained in the files COBTHRED.DLE (for DOS) and COBTHRED.DLL (for OS/2).
This support MUST be installed in the system by specifying the file name in
the INSTALL section of a .CFG file (see Build chapter in the Run Time
Environment Operating Guide). If you are using Workbench or the Run Time
Environment then this will be MFWB.CFG or RUN.CFG respectively, otherwise it
should be included in the .CFG file you have created when Building your
application.
1.4 Example Program
--------------------
The supplied example program MTHELLO.CBL is a simple demonstration of how
to use the above call. This example creates a number of threads each of
which updates a different position on the screen with a box that flashes
on or off.
1.5 Thread Local Data And Shared Data
--------------------------------------
In this implementation, any data that you wish to be shared amongst all threads
must be declared as being EXTERNAL in its WORKING-STORAGE definition. Any
data not marked as EXTERNAL will be assumed to be thread local.
1.6 Creating A New Thread Of Execution
---------------------------------------
A new thread of execution is initiated by making the following call :
CALL OS2API "PC_CREATE_THREAD" USING BY REFERENCE thread-id,
BY REFERENCE entry-name,
BY VALUE stack-size SIZE 2
where parameters are as follows :
thread-id PIC X(4) on exit, contains a handle that
uniquely identifies the new thread.
This handle is known as the thread-id.
entry-name PIC X(n) on entry, contains the space-terminated
entry point at which the thread is to
start execution
stack-size PIC XX COMP-5 on entry, this contains the size of
the stack to be allocated to the new
thread. A stack size of zero means
that the new thread should inherit the
stack size of its creator thread.
It should be noted that there is only
approximately 50K of stack space
available in the run-time within
which all thread stacks must be
allocated. The stack size of the first
COBOL thread is always 8K bytes.
A minimum stack size of 2K is
recommended
and where OS2API has been defined to be CALL CONVENTION 3 in the SPECIAL
NAMES section of the program.
This call commences a new thread of execution at the COBOL entry point
defined by 'entry-name'. The new thread in the program containing the
entry point will have its Working-Storage section (i.e. thread local data)
initialised to the current value of the Working-Storage in the copy of the
program that exists in the creating thread. If the program did not exist
in the creating thread, then the Working-Storage will be initialised as for
a fresh program load.
The new thread will inherit the command line, all open libraries and all
open COBOL files from the creating thread.
1.7 Thread Termination
-----------------------
A particular thread of execution terminates when it executes a STOP RUN
statement. You must ensure that all secondary threads have been terminated
before actually terminating the initial thread.
1.8 Restrictions
-----------------
Multi-threaded applications can only be executed in protected mode. This
means you must use either OS/2 or XM on DOS.
Also, full multi-threading is only supported in INT/GNT programs. You can
not use this call to multi-thread a linked OBJ program. However, you can
use it to execute different OBJ programs in different threads.