0

私は銀行家のアルゴリズムに取り組んでおり、ループを使用してスレッドを作成しています。問題は、5 つのスレッドを作成する必要がある場合に、4 つのスレッドのみを作成するループが発生することです。ループを調べたところ、何かが欠けていない限り、すべてが正しいようです。

/* these may be any values >= 0 */

#define NUMBER_OF_CUSTOMERS 5
#define NUMBER_OF_RESOURCES 3

/* the available amount of each resource */
int available[NUMBER_OF_RESOURCES];

/*the maximum demand of each customer */
int maximum[NUMBER_OF_CUSTOMERS][NUMBER_OF_RESOURCES];

/* the amount currently allocated to each customer */
int allocation[NUMBER_OF_CUSTOMERS][NUMBER_OF_RESOURCES];

/* the remaining need of each customer */
int need[NUMBER_OF_CUSTOMERS][NUMBER_OF_RESOURCES];

int release_resources(int customer_num, int release[]){
   allocation[customer_num][NUMBER_OF_RESOURCES];
   return 1;
}

pthread_mutex_t mutex;

int main(int argc, char *argv[]){

  pthread_mutex_init(&mutex, NULL);

  pthread_t threads [3];
  int result;
  unsigned index;

  for(index = 0; index < NUMBER_OF_RESOURCES; index++){
    available[index] = strtol(argv[index+1], NULL,10);
  } 

  for(index = 0; index < NUMBER_OF_CUSTOMERS; ++index){
    printf("\nCreating thead %d", index);
    result = pthread_create(&threads[index],NULL,release_resources,1);  
  }

  //printf("Done");
  return 0;
}
4

1 に答える 1