示例#1
0
void *barber(void *junk) {
    // While there are still customers to be serviced...
    // Our barber is omnicient and can tell if there are 
    // customers still on the way to his shop.
    while (!allDone) {

  // Sleep until someone arrives and wakes you..
  printf("The barber is sleeping\n");
  sem_wait(&barberPillow);

  // Skip this stuff at the end...
  if (!allDone) {

      // Take a random amount of time to cut the
      // customer's hair.
      printf("The barber is cutting hair\n");
      randwait(3);
      printf("The barber has finished cutting hair.\n");

      // Release the customer when done cutting...
      sem_post(&seatBelt);
  }
  else {
      printf("The barber is going home for the day.\n");
  }
    }
}
示例#2
0
void *customer(void *number) {
    int num = *(int *)number;

    // Leave for the shop and take some random amount of
    // time to arrive.
    printf("Customer %d leaving for barber shop.\n", num);
    randwait(5);
    printf("Customer %d arrived at barber shop.\n", num);

    // Wait for space to open up in the waiting room...
    sem_wait(&waitingRoom);
    printf("Customer %d entering waiting room.\n", num);

    // Wait for the barber chair to become free.
    sem_wait(&barberChair);
    
    // The chair is free so give up your spot in the
    // waiting room.
    sem_post(&waitingRoom);

    // Wake up the barber...
    printf("Customer %d waking the barber.\n", num);
    sem_post(&barberPillow);

    // Wait for the barber to finish cutting your hair.
    sem_wait(&seatBelt);
    
    // Give up the chair.
    sem_post(&barberChair);
    printf("Customer %d leaving barber shop.\n", num);
}
示例#3
0
void *barber(void *junk) {
    while (!allDone) {

	printf("Zzzzzz\n");
	sem_wait(&barberPillow);

	if (!allDone) {

	    printf("Fryzjer tnie wlosy\n");
	    randwait(3);
	    printf("Fryzjer zcial wlosy.\n");
	    sem_post(&seatBelt);
	}
	else {
	    printf("Fajrant.\n");
	}
    }
}
void *barber(int i)
{
	while(!over)
	{
		if(!over)
		{	
			printf("\nBarber %d is sleeping",i);
			sem_wait(&wake_barber);
		
			printf("\nBarber %d is cutting hair",i);
			randwait(1);
			printf("\nBarber %d has finished cutting the hair",i);
			sem_post(&seatbelt);
		}
	
		else
		{
			printf("\nThe barber %d is done for the day",i);
		}
	}
	pthread_exit(0);
}		
示例#5
0
void *customer(void *number) {
    int num = *(int *)number;

    printf("Klient %d idzie sie golic.\n", num);
    randwait(5);
    printf("Klient %d przyszedl do salonu.\n", num);

    sem_wait(&waitingRoom); // Wait for place
    printf("Klient %d wszedl do poczekalni.\n", num);
	// Wait for chair
    sem_wait(&barberChair);
	// Set place free
    sem_post(&waitingRoom);
	// Wake the barber
    printf("Klient %d budzi fryzjera.\n", num);
    sem_post(&barberPillow);

    sem_wait(&seatBelt);

    sem_post(&barberChair);
    printf("Klient %d wychodzi, wlosy zostaja.\n", num);
}