The multiple conversations functionality enables a CPI-C client to hold several conversations at once within a program run. The conversations can be established with different UTM server applications or the same UTM server application.
The UPIC carrier system supports multiple conversations only on systems which support multithreading (e.g. Unix, Linux and Windows systems). For more information, see "Multithreading".
Multithreading means that several threads can be started within the process in which a program is running. Threads are program segments running in parallel within a process, in which processing steps are processed independently of each other. Threads are therefore often called concurrent processes. The use of threads is equivalent to a type of multiprocessing that is administered by the program itself and is executed in the same process as the program itself.
CPI-C clients which run on systems with multithreading and are implemented accordingly can therefore be connected to several UTM services at the same time.
CPI-C clients which run on systems that do not support multithreading can only hold one conversation at a time. Only when this conversation is shut down can a new one be established.
If a client application wants to process several conversations at once, each one of these conversations must be processed in a separate thread independently of the others. Here you must note the following:
The first thread of the process in which the other threads are started is the main thread. A conversation can also be established in the main thread, as in any other process.
For each additional conversation that the program is to establish and process in parallel, a thread must be started explicitly. System calls are provided for starting the threads. These system calls are dependent on the operating system and on the compiler used (see example on "Multiple conversations (Unix, Linux and Windows systems)").
In each of the started threads, the runtime environment for the CPI-C client must be started. For this purpose, an Enable_UTM_UPIC call must be issued in every thread. The CPI-C program can sign on in all threads with the same or with different names.
In each individual thread the conversation characteristics must be set with an Initialize_Conversation call. The conversation is assigned a separate conversation ID by UPIC.
Each conversation ID can only be used within the thread in which the associated conversation was initialized and established. If the conversation ID is specified in another thread in a CPI-C call, UPIC brings back the return code CM_PROGRAM_PARAMETER_CHECK.
In each thread the program must sign off from UPIC with Disable_UTM_UPIC before the thread is terminated.
The main thread must not terminate until all other threads have signed off and terminated.
The sequences within the client program are shown in the following diagram.
Upic local
Figure 15: Starting several threads within a process (Unix, Linux and Windows systems)
(the gray-hatched area corresponds to the process in which the client program is running)
The schema belonging to the client program is structured as follows:
void main () 1. { ... thrd[0] = CreateThread(...,UpicThread,...); 2. thrd[1] = CreateThread(...,UpicThread,...); ... Enable_UTM_UPIC (...); 3. ... /* Calls for establishing and processing a conversation */ /* in the main thread: */ Initialize_Conversation (...) ... Allocate (...) .... Send_Data (...) ... Receive (...) ... Disable_UTM_UPIC (...); ... WaitforMultipleObjects(2,&thrd[0],...); 4. ExitProcess (0); 5. } DWORD WINAPI UpicThread(LPVOID arg) 6. { ... Enable_UTM_UPIC (...); ... /* Calls for establishing and processing conversation in thread */ /* as in main thread under 3. */ ... Disable_UTM_UPIC (...); ... ExitThread(0); 7. }
Process and main thread are started.
Two further threads are started via the corresponding system call. The system call depends on the system and compiler used.
Each thread is started with the UpicThread() function. In UpicThread() a conversation is established and processed. UpicThread is a freely selectable name.Each thread must explicitly execute an Enable_UTM_UPIC call and a Disable_UTM_UPIC call. At this point the main thread signs on to UPIC. After the Enable_UTM_UPIC call the CPI-C calls can then be issued for establishing a conversation in the main thread and processing this conversation. Several conversations can be processed consecutively in the main thread. Once the conversation in the main thread has terminated, this thread must sign off with Disable_UTM_UPIC.
The main thread waits until both the threads it has started have terminated.
End of the process and the main thread.
UpicThread() is the function that is called when a new thread is started. In this function, the relevant thread signs on to UPIC with Enable_UTM_UPIC() and processes “its conversation” (with Initialize_Conversation(), Set_..., Send_Data(), Receive() ...). Here too, several conversations can be processed consecutively. When the last conversation has terminated, the thread signs off with Disable_UTM_UPIC.
UpicThread() must be programmed such that the threads running concurrently do not interfere with each other. The code must therefore be structured so that it can be executed by several threads at the same time, i.e. the functions used must not mutually destroy the context.
Termination of the thread.
openUTM-Client comes with the source code for a sample program on multiple conversations (see section “Sample programs for Windows systems”).