CORBA 2.6 Programmer's Guide for C++
Create a thread●
Yield control of the processor●
Wait for other threads to complete●
Cancel a thread●
Save and retrieve thread-specific data●
Also provided are two concurrency-control mechanisms: mutexes and condition variables. For mutexes, you can perform the
following operations:
Create a mutex●
Lock a mutex●
Unlock a mutex●
Test a mutex●
For condition variables, you can perform the following operations:
Create a condition variable●
Wait on a condition variable●
Signal availability of a condition variable●
Broadcast availability of a condition variable●
These operations are implemented by the Fw_Thread class, defined in the header file vthread.h in the
$NSD_ROOT/include/nsdevent product subdirectory. Refer to the NonStop CORBA 2.6 Programmer's Reference for a
detailed description of these classes and their methods.
HP recommends that NonStop CORBA applications use the vthread API for multithreading because it is object-oriented and easier to
use than the POSIX threading (pthread) API. However, if you require conformance to POSIX threading standards, you can use the
underlying threading implementation for the specific platform. In the OSS environment, the vthread API is built on the NonStop
DCE pthread package, which is included in the $NSD_ROOT/include directory. For detailed information about using the pthread
API, refer to the NonStop DCE Application Programming Guide.
Caution: Although you should refer to the NonStop DCE Application Programming Manual for information about the pthread
API, do not use the libraries provided by the NonStop DCE product; doing so may interfere with the operation of the
NonStop CORBA ORB. Instead, use the version of the pthread.h header file provided in the
$NSD_ROOT/include directory, which includes the pthread API and the supported jacket procedures.
Creating and Using Threads
To create and use threads through the vthread API, perform the following steps:
Include the $NSD_ROOT/include/nsdevent/vthread.h header file in your program:
#include <nsdevent/vthread.h>
1.
Create a function that will be the body of a thread in the global area of your application; for example:
void my_function (void* threadArg);
This function cannot be a class instance method; otherwise a compiler error occurs. In addition, the function must have the
signature expected by the thread-generating function described in Step 3. The threadArg parameter is needed for
communication between the thread function and the thread-generating function.
2.
Create a member function that invokes a thread-generating function that uses the thread function created in Step 2:
Fw_Thread::Id_ptr threadId =
Fw_Thread::create ("My Thread", (Fw_Thread::Function) my_function, void* param3,
Fw_Thread::Default_Priority);
The first parameter of the Fw_Thread::create function is a string defining the name of the thread. The second parameter
3.