ADM-XRC SDK 2.8.1 User Guide (Linux)
© Copyright 2001-2009 Alpha Data


Multithreading issues (ADMXRC interface)

The ADM-XRC SDK is designed to be thread-safe. The ADMXRC interface functions can be divided into two groups:

The latter group of functions, those which are capable of blocking the calling thread, require a pointer to a Win32 event (PHANDLE) to be passed. Unless great care is taken to ensure that no two threads use the same event at the same time, this event must be private to each thread using the API.

The requirement for a per-thread event stems from the need to specify an event in overlapped DeviceIoControl calls (see Win32 API). The Microsoft Platform SDK documentation states that events used in an overlapped DeviceIoControl call must be manual-reset events. A code fragment for creating a suitable event for use with the blocking ADM-XRC API calls is:

/* Create a manual reset Win32 event */
event = CreateEvent(NULL, TRUE, FALSE, NULL);
if (event == NULL) {
    /* Error handling */
    ....
}

A pointer to the event, event, can then be passed to the blocking API functions.

The API also allows the user to specify a NULL value for the PHANDLE. In that case, the API creates and returns a manual-reset event, on the calling thread's behalf. This is intended simply as a shortcut to remove the need for the above code fragment. It is good practice for a thread to close its event using the Win32 CloseHandle function before terminating, although any open handles that remain are closed automatically when the parent process of the thread terminates.

 


 Top of page