MPIThreadFunction
Declaration
typedef MPI_RESULT (MPI_DECL2 *MPIThreadFunction)(void *threadData);
Required Header: stdmpi.h
Change History: Added in 04.00.
Description
MPIThreadFunction is the type definition for the function to be launched in a new thread by MPIThread objects.
Functions with an identical signature may be used as thread functions.
Note: Exceptions that occur in the thread function must not propagate back into the MPI library. This causes the parent thread to exit as possibly cause the application to crash. This applies to C++ exceptions, which can occur on any operating system, but also to Microsoft’s structured exceptions which is found on Windows® operating systems.
threadArgs | The MPIControl object handle associated with the controller that generated the event. |
---|
Return Values
When the thread function exits, the thread ends and the thread function return value will be stored in the MPIThread object and may be retrieved by mpiThreadStatus(…).
Sample Code
MPI_RESULT MPI_DECL2 helloThreadMain(void* threadData) { /* print event type to screen. */ printf("Hello from another thread.\n" " threadData = 0x%08x", threadData); return MPIMessageOK; } /* Wait for a thread to end */ MPI_RESULT threadJoin(MPIThread thread) { MPIThreadStatus status; MPI_RESULT returnValue = MPIMessageOK; while (returnValue == MPIMessageOK) { returnValue = mpiThreadStatus(thread, &status); if ((returnValue == MPIMessageOK) && (status.active == FALSE)) { break; } mpiPlatformSleep(10); } return returnValue; } void sayHello() { MPIThread thread; MPI_RESULT returnValue; returnValue = mpiThreadCreate(&thread, NULL); msgCHECK(returnValue); returnValue = mpiThreadStart(thread, helloThreadMain, NULL); msgCHECK(returnValue); returnValue = threadJoin(thread); msgCHECK(returnValue); returnValue = mpiThreadDelete(thread); msgCHECK(returnValue); }