コード例 #1
0
ファイル: narrow-bridge.c プロジェクト: 2ral/pintos
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);
}
コード例 #2
0
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;
}
コード例 #3
0
/*
 * 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;
}