mpiThreadCreate

Declaration

MPI_DECL1 MPI_RESULT MPI_DECL2
    mpiThreadCreate(MPIThread        *thread,
                    MPIThreadOptions *options);

 

Required Header: stdmpi.h

Change History: Added in 04.00.

Description

mpiThreadCreate creates a thread object. mpiThreadCreate is the equivalent of a C++ constructor.

Note: mpiThreadCreate does not start a new thread. To start a new thread, call mpiThreadStart after a thread object is created.

thread A pointer to an MPIThread handle.
options Options for the thread. If options is NULL, the system default values is used.

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

mpiThreadDelete | mpiThreadValidate