MPIThreadStatus

Declaration

typedef struct MPIThreadStatus {
    void           *id;             /* platform-specific thread id */
    MPI_BOOL       active;          /* FALSE => thread not active */
    MPI_RESULT     returnValue;     /* thread-specific return value */
} MPIThreadStatus;

 

Required Header: stdmpi.h

Change History: Added in 04.00.

Description

MPIThreadStatus holds status information for an MPIThread object.

id The type of event generated by the controller.
active The state of the thread.

If active is TRUE, the thread function has not yet completed.

If active is FALSE, the thread function has completed and returnValue hold the thread function’s return value.
returnValue The return value of the thread function.

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);
}

See Also

mpiThreadStatus