示例#1
0
int main( int argc, char *argv[] )
{

    // Set the mutexes to fast locking semantics
    setkind( HTHREAD_MUTEX_FAST_NP );

    // Print out a banner for the first attempt
    printf( "----------------------------------------------------------------------\n" );
    printf( "- Fast Lock: First Lock Attempt                                      -\n" );
    printf( "----------------------------------------------------------------------\n" );
    lock();

    // Print out a banner for the second attempt
    printf( "----------------------------------------------------------------------\n" );
    printf( "- Fast Lock: Second Lock Attempt                                     -\n" );
    printf( "----------------------------------------------------------------------\n" );
    lock();

    // Print out a banner for the third attempt
    printf( "----------------------------------------------------------------------\n" );
    printf( "- Fast Lock: Third Lock Attempt                                      -\n" );
    printf( "----------------------------------------------------------------------\n" );
    lock();

    // Finish the program
	printf( "-- QED --\n" );

	return 1;
}
示例#2
0
int main( int argc, char *argv[] )
{
    Huint mid;
    Huint sta;

    // Set the mutexes to fast locking semantics
    setkind( HTHREAD_MUTEX_ERRORCHECK_NP );

    // Print out a banner for the first attempt
    printf( "----------------------------------------------------------------------\n" );
    printf( "- Error Lock: First Lock Attempt                                     -\n" );
    printf( "----------------------------------------------------------------------\n" );

    // Lock all of the mutexes
    for( mid = 0; mid < MUTEX_MAX; mid++ )
    {
        // Attempt to acquire the mutex for thread id 0
        sta = _mutex_acquire( 0, mid );

        // Print out the status information that was returned
        printf( "LOCK: (MID=%d) (STA=0x%8.8x)\n", mid, sta );
    }

    // Print out a banner for the second attempt
    printf( "----------------------------------------------------------------------\n" );
    printf( "- Error Lock: Second Lock Attempt                                    -\n" );
    printf( "----------------------------------------------------------------------\n" );

    // Try to lock all of the mutexes again
    for( mid = 0; mid < MUTEX_MAX; mid++ )
    {
        // Attempt to acquire the mutex for thread id 0
        sta = _mutex_acquire( 0, mid );

        // Print out the status information that was returned
        printf( "LOCK: (MID=%d) (STA=0x%8.8x)\n", mid, sta );
    }
    
    // Finish the program
	printf( "-- QED --\n" );

	return 1;
}
示例#3
0
int main( int argc, char *argv[] )
{
    // Set the mutexes to fast locking semantics
    setkind( HTHREAD_MUTEX_RECURSIVE_NP );

    lock();
    count();
    lock();
    count();
    unlock();
    count();
    unlock();
    count();

    // Finish the program
	printf( "-- QED --\n" );

	return 1;
}