int main()
{
  pthread_t  t1, t2, t3;

  my_main_start();

  my_obj_reg(&data);

  my_mutex_init(&A, NULL);
  my_mutex_init(&B, NULL);
  my_mutex_init(&C, NULL);

  my_thread_create(&t1, 0, thread_routine_1, 0);
  my_thread_create(&t2, 0, thread_routine_2, 0);
  my_thread_create(&t3, 0, thread_routine_3, 0);

  my_thread_join(t1, 0);
  my_thread_join(t2, 0);
  my_thread_join(t3, 0);

  my_mutex_destroy(&A);
  my_mutex_destroy(&B);
  my_mutex_destroy(&C);

  my_main_end();

  return 0;
}
Exemplo n.º 2
0
/*
	RunTest

		This function runs a particular test for a number of times and reports the result.

	Parameters
		func	A function with the test
		str		A string with the test name

	Return Value
		None. This function prints the result

*/
void RunTest( void * ( * func)( void * ), char * str )
{
	// ------------------ Local Variables --------------------

		int testnum;
		int passedtests;
		double timesum;
		pthread_t *threads;
		ThreadParameters_t *threadparameters;

	// ------------------- Initialization -------------------

		passedtests = 0;
		timesum = 0;
		printf( "Now running [%s]\n", str );

	// ------------------- Run Tests ------------------------

		for ( testnum = 0; testnum < REPEATTESTS; testnum++ )
		{

			my_mutex_init( &gMutex );
			my_barrier_init( &gBarrier, gP );

			CreateThreads( &threads, gP, func, &threadparameters );
			JoinThreads( &threads, gP, &threadparameters );

			my_mutex_destroy( &gMutex );
			my_barrier_destroy( &gBarrier );

			timesum += gElapsedTime;
			if ( gCorrectTest )
			{
				passedtests++;
				printf( "+" ); fflush( stdout );
			}
			else
			{
				printf( "-" ); fflush( stdout );
			}
		}

		timesum /= REPEATTESTS;


	// ------------------- Print Outcome ---------------------
		printf( "\nTests passed: %d of %d. Average Time = %f (sec)\n", passedtests, REPEATTESTS, 
			 timesum );
}