Customizing Multi-threading Services

Although the SOM kernel and the other SOMobjects frameworks allow applications to be multi-threaded, the kernel and frameworks generally do not require or exploit threads themselves. But there are some exceptions: for example, application servers in DSOM can be configured so that each incoming request is executed on a separate thread.

An application may choose to employ "native" multi-threading services provided by the underlying operating system (for example, OS/2). On other operating systems that do not support native multi-threading (such as, AIX 3.2), thread support may be provided as part of particular programming environments (like DCE) or libraries. SOM provides a mechanism that allows an application to define and customize the multi-threading services used by SOMobjects frameworks.

Four thread service functions are defined for use by SOMobjects frameworks. These functions may be called indirectly via the global pointer variables defined below. A somToken parameter (called "thrd" below) is used as a generic "handle" to refer to a thread # usually it is a pointer to a thread id or descriptor. The actual representation of the thread handle is hidden by the functions.

typedef void somTD_SOMThreadProc(void * data);

unsigned long (*SOMStartThread)(somToken *thrd,
                                somTD_SOMThreadProc proc,
                                void *data,
                                unsigned long datasz,
                                unsigned long stacksz);
unsigned long (*SOMEndThread)(void);
unsigned long (*SOMKillThread)(somToken thrd);
unsigned long (*SOMGetThreadHandle)(somToken * thrd);

The actual mutex service function prototypes and global variable declarations are found in file "somthrd.h".

If the underlying operating system supports native multi-threading (currently, only OS/2), SOM provides appropriate default multi-threading service function implementations. On those operating systems that do not support native multi-threading, the default multi-threading service functions have null implementations.

An application may want to use threading services different from those provided by the underlying operating system (if any); for example, DCE applications will want to use DCE threads. In that case, the default multi-threading service functions can be replaced by application#defined functions.

An application program would use code similar to the following to install the replacement routines:

#include <somthrd.h>/* Define a replacement routine: */
unsigned long myStartThread (somToken *thrd,
                             somTD_SOMThreadProc proc,
                             void *data,
                             unsigned long datasz,
                             unsigned long stacksz)
{
    (Customized code goes here)
}
...    
SOMStartThread =myStartThread;

It is important to install custom multi-threading service functions before any SOM calls are made.


[Back: Customizing Mutual Exclusion Services (Thread Safety)]
[Next: Distributed SOM (DSOM)]