Example #1
0
/**
 * main
 *
 * executable entry point
 */
INT __cdecl main( INT argc, CHAR **argv )
{

    /* PAL initialization */
    if( (PAL_Initialize(argc, argv)) != 0 )
    {
        return( FAIL );
    }

    /* set the thread priority of the main to the highest possible value
       this will give the chance to the main thread to create all the
       other threads */
    if(!SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_NORMAL))
    {
        DWORD dwError;

        dwError = GetLastError();
        Fail( "Unexpected SetThreadPriority() failure with error %d\n",
			  dwError );
    }

    CheckThreadPriority( GetCurrentThread(), THREAD_PRIORITY_NORMAL );
    //Add verification of timing out here..
    PAL_Terminate();
    return PASS;
}
Example #2
0
/**
 * ThreadFunc
 *
 * Thread function that sets its own priority to the priority
 * value in the global array nPriority[] at the index specified
 * as an argument to the thread function.
 */
DWORD PALAPI ThreadFunc( LPVOID param )
{
    int i, j, k;
    int index;
    int total = 0;
    time_t start;
    time_t finish;
    long duration;
    DWORD dwError = 0;

    /* cast function argument to a thread priority value */
    index = (int)param;
    if( index < 0 || index >= NUM_THREADS )
    {
        Fail( "Thread index argument was out of range, value was %d\n",
              index );
    }

    /*
     * check the old thread priority, it should be THREAD_PRIORITY_NORMAL,
     * if not it could potentially be a bug in GetThreadPriority() and not
     * in CreateThread() -- at the very least it provides us with a known
     * thread priority value to test against under a known condition even
     * if it's a trivial one.
     */
    CheckThreadPriority( index, THREAD_PRIORITY_NORMAL );


    /* set the new thread priority */
    if( ! SetThreadPriority( hThread[index], nPriority[index] ) )
    {
        dwError = GetLastError();
        Fail( "Unexpected SetThreadPriority() failure with error %d\n",
			  dwError );
    }

    /* time this thread's duration */
    time( &start );

    /* check the new thread priority */
    CheckThreadPriority( index, nPriority[index] );

    /*
     * Do a lengthy benign operation
     */
    for( i=0; i<1000; i++ )
    {
        for( j=0; j<1000; j++ )
        {
            total = j * i;
            for( k=0; k<1000; k++ )
            {
                total += k + i;
            }
        }
    }

    /* finish timing the thread and calculate the duration */
    time( &finish );
    duration = (long)(finish - start);

    /* update the elapsed time array */
    nElapsedTime[ index ] = duration;

    return 0;
}