CORBA 2.3.3 Programmer's Guide for C++
Chapter 8. Writing Multithreaded Applications
Prev
Next
Chapter 8. Writing Multithreaded Applications
Table of Contents
Overview of Multithreading
Multithreading in Client Applications
Multithreading in Server Implementations
Using the NonStop CORBA Portable Threading (vthread) API
Creating and Using Threads
Using the yield(), join() and cancel() Methods
Creating and Using a Mutex
Creating and Using a Condition Variable
Saving and Retrieving Thread-Specific Data
Terminating Execution of a Thread
Detaching a Thread
Error Reporting from vthread Methods
Using a Timer for a Thread
This section describes how to make appropriate threading decisions and write multithreaded NonStop CORBA applications.
For C++ programmers, NonStop CORBA provides an object-oriented, portable API for multithreading, which is described under
Using the NonStop CORBA Portable Threading (vthread) API.
For several examples of explicit multithreading in a NonStop CORBA application, refer to the Bank sample application. The client
wrapper uses mutexes, and the server wrapper uses condition variables. The feed program uses a timer and includes several uses of
multithreading. Multithreading in the feed program reduces the number of processes that are needed to generate workload for the
application.
Overview of Multithreading
Multithreading is a programming paradigm that enables logically concurrent execution. A thread is a sequence of running code that
coexists with other threads in the same address space. Each thread has its own execution stack, but shares the process instruction
space with other threads. Having multiple threads in a process means that there are many apparently simultaneous points of
execution. Multithreading simplifies programming tasks by allowing you to write a single code sequence as if it were alone and
have it run as many threads. By writing different threads to handle different tasks, you can easily divide the problem space.
Multithreading can also increase the throughput of a process without incurring the overhead of creating multiple processes.
The NonStop CORBA ORB itself is multithreaded, and it provides automatic multithreaded dispatching of requests to servants
through its implementation of the default POA threading policy, ORB_CTRL_MODEL. The same servant can be accessed by
multiple threads. You can also explicitly create additional threads in your applications. In a distributed NonStop CORBA
application, you can use multithreading in the client, the server, or both. You can use multithreading with or without server pools.
Some applications lend themselves better to multithreading than others. Multithreading can be useful when:
Interacting with another object or process that may be slow in responding●
Interacting with a user who may not respond immediately●