Exemple #1
0
static void *OneVehicle(void *cardirect)
{
	direction direct = (direction)cardirect;
	ArriveBridge(direct);
	OnBridge(direct);
	ExitBridge(direct);
	return NULL;
}
Exemple #2
0
void OneVehicle(int direc, int prio) {
  
  ArriveBridge(direc,prio);
  
  CrossBridge(direc,prio);
  
  printf("%s %d %s %d\n","CROSSED          Origin =",direc,"Priority =",prio);

  ExitBridge(direc,prio);
}
void * Train ( void *arguments )
{
	TrainInfo	*train = (TrainInfo *)arguments;

	/* Sleep to simulate different arrival times */
	usleep (train->length*SLEEP_MULTIPLE);

	ArriveBridge (train);
	CrossBridge  (train);
	LeaveBridge  (train); 

	free (train);
	return NULL;
}
/*
 * This function is started for each thread created by the
 * main thread.  Each thread is given a TrainInfo structure
 * that specifies information about the train the individual 
 * thread is supposed to simulate.
 */
void * Train ( void *arguments )
{
  TrainInfo	*train = (TrainInfo *)arguments;

  /* Sleep to simulate different arrival times */
  usleep (train->length*SLEEP_MULTIPLE);

  ArriveBridge (train);
  CrossBridge  (train);
  LeaveBridge  (train); 

  /* I decided that the paramter structure would be malloc'd 
   * in the main thread, but the individual threads are responsible
   * for freeing the memory.
   *
   * This way I didn't have to keep an array of parameter pointers
   * in the main thread.
   */
  free (train);
  return NULL;
}