mpiThreadStart

Declaration

MPI_DECL1 MPI_RESULT MPI_DECL2
    mpiThreadStart(MPIThread         thread,
                   MPIThreadFunction function,   /* NULL invalid */
                   void              *argument);

 

Required Header: stdmpi.h

Change History: Added in 04.00.

Description

mpiThreadStart starts a new thread.

thread A handle to the MPIThread object.
function The function the new thread executes.
argument The argument to pass to 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

MPIThreadFunction