Customizing Mutual Exclusion Services (Thread Safety)

The SOM kernel and the other SOMobjects frameworks (DSOM, Persistence, Replication, and so on), have been made thread safe with respect to multi-threaded processes. As used here, "thread safe" means that the SOMobjects run time has been implemented using mutual exclusion semaphores to protect sections of the code which must only be executed by a single thread in a multi-threaded application process at one time.

Some operating systems provide native multi-threading (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.

It is vital that SOM employ the mutex services that are provided by the thread package used by the application. Consequently, SOM provides a mechanism for defining and customizing mutex services.

Five mutex service functions are used to implement mutual exclusion in SOM. These functions are called indirectly via the global pointer variables defined below. A somToken parameter (called "sem" below) is used as a generic "handle to refer to a mutex semaphore - usually it is a pointer to a mutex semaphore variable or data structure. The actual representation of the mutex semaphore is hidden by the functions.

unsigned long (*SOMCreateMutexSem)(somToken *sem);
unsigned long (*SOMRequestMutexSem)(somToken sem);
unsigned long(*SOMReleaseMutexSem)(somToken sem);
unsigned long (*SOMDestroyMutexSem)(somToken sem);
unsigned long (*SOMGetThreadId)();

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

If the underlying operating system supports native multi-threading (currently, only OS/2), SOM provides appropriate default mutex service function implementations. On those operating systems that do not support native multi-threading, the default mutex 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 mutex 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 <som.h>/* Define a replacement routine: */
unsigned long myCreateMutexSem (somToken *sem)
{
    (Customized code goes here)
}
...      
SOMCreateMutexSem= myCreateMutexSem;

It is important to install custom mutex service functions before any SOM calls are made.


[Back: Customizing Error Handling]
[Next: Customizing Multi-threading Services]