Ejemplo n.º 1
0
void q3(void)
{
  
  int i = 0;
    
  /* initialize the timer to keep track of customers time in shop */
  time_in_shop = stat_timer();
  
  /* initialize the counter to keep track of number of customers in the shop */
  customer_in_shop = stat_counter();
  
  /* initialize the counter to keep track of status of barber's chair*/
  bchair_stat = stat_counter();

  /* declaring the barber thread */   
  pthread_t barber;
 
  /* creating the barber thread */ 
  pthread_create(&barber, NULL, barber_thread, (void*) -1);
 
  /* declaring the customer thread */ 
  pthread_t cust;

  for( i=0; i < cust_threads; i++)
  {
      /* creating the customer thread */ 
      pthread_create(&cust , NULL, customer_thread, (void*) i);
  }

  wait_until_done();
  
  /* average number of customers turned away */
  float avg_cust = (float) cust_turned_away/total_cust_entered;
  
  /* Average number of customers in the shop */
  double avg_customer_in_shop = stat_count_mean(customer_in_shop);
  
  /* Average time spent in the shop by a customer who does not find a full shop */
  double avg_cust_time_shop = stat_timer_mean(time_in_shop);
  
  /* Fraction of time someone is siting on the barber's chair */
  double avg_bchair_stat = stat_count_mean(bchair_stat);

  printf("Fraction of customer visits result in turning away due to a full shop = %f \n", avg_cust);
  printf("Average time spent in the shop by a customer who does not find a full shop = %f \n", avg_cust_time_shop);
  printf("Average number of customers in the shop = %f \n", avg_customer_in_shop);
  printf("Fraction of time someone is siting on the barber's chair  = %f \n", avg_bchair_stat);
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
    int i;
    qthread_t t;

    signal(SIGINT, handler);
    init_time();
    nforks = 4;

    qthread_mutex_init(&m, NULL);
    for (i = 0; i < nforks; i++)
        qthread_cond_init(&C[i], NULL);

    for (i = 0; i < nforks; i++) 
        qthread_create(&t, NULL, philosopher_thread, (void*)i);

    wait_until_done();

    return 0;
}
Ejemplo n.º 3
0
void q2(void)
{
    int i = 0;
    
    /* declaring the barber thread */ 
    pthread_t barber;
    
    /* creating the barber thread */ 
    pthread_create(&barber, NULL, barber_thread, (void*) -1);
    
    /* declaring the customer thread */ 
    pthread_t cust;

    for( i=0; i < cust_threads; i++)
    {
    
       /* creating the customer thread */ 
       pthread_create(&cust , NULL, customer_thread, (void*) i);
    
    }

    wait_until_done();
    
}