title: Bankers Algorithm thread creation not running the passed method completely
body: <p>My request_resources method isn't being ran when I call it from a thread creation in my main. It should be creating a thread, requesting resources, checking safe state and then exiting. I'm not sure why it stalls after 2 threads and gives no output from the test statements in the methods. </p>
  
  <pre><code>        #include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;unistd.h&gt;
  #include&lt;pthread.h&gt;
  #include&lt;semaphore.h&gt;
  
  
  /* these may be any values &gt;= 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];
  
  pthread_mutex_t mutex =
  PTHREAD_MUTEX_INITIALIZER;
  
      int safe_state(int customer_num){
          int work[NUMBER_OF_CUSTOMERS];
          int done;
          for(int w = 0; w &lt; NUMBER_OF_CUSTOMERS; w++){
              work[w] = available[w];
              printf("%d", work[w]);
          }
  
          int finish[NUMBER_OF_CUSTOMERS];
  
          for(int i = 0; i &lt; NUMBER_OF_CUSTOMERS; i++){
              finish[i] = 0;
          }
  
          for(int k = 0; k &lt; NUMBER_OF_CUSTOMERS; k++){
              if(finish[k] == 0 &amp;&amp; need[customer_num][k] &lt;= work[k]){
                  work[k] += allocation[customer_num][k];
                  finish[k] = 1;
              }
              else{
                  done = -1;
                  break;
              }
          }
  
          for(int x = 0; x &lt; NUMBER_OF_CUSTOMERS; x++){
              if(finish[x] == 0){
                  done = 1;
              }
              else{
                  done = -1;
              }
          }
          printf("\n jj %d", done);
  
          return done;
  
      }
  
  
      int* request_resources(int customer_num, int request[]){
          pthread_mutex_lock(&amp;mutex);
          int pass = 2;
          for(int i = 0; i &lt; NUMBER_OF_RESOURCES; i++){
              if(request[i] &lt;= need[customer_num][i] &amp;&amp; request[i] &lt;= available[i]){
                  printf("Sata"); 
                  int state = safe_state(customer_num);
                  if(state == 1){
                      available[i] -+ request[i];
                      allocation[customer_num][i] += request[i];
                      need[customer_num][i] -+ request[i];
                      pass = 1;
  
                  }
                  else{
                      printf("This results in unsafe state\n");
                      pass = -1;
                      break;
                  }
              }
              else{
                  printf("Not enough resources\n");
                  pass = -1;
                  break;
              }
          }
          printf("I'm a thread\n");
          pthread_mutex_unlock(&amp;mutex);
          return pass;
  
      } 
  
      int release_resources(int customer_num, int release[]){
  
      }
  
  
  
  
  int main(int argc, char *argv[]){
  
  
  
      pthread_t threads [NUMBER_OF_CUSTOMERS];
      int result;
      unsigned index = 0;
  
      for(index = 0; index &lt; NUMBER_OF_RESOURCES; index++){
          available[index] = strtol(argv[index+1], NULL,10);
      }   
  
      int req[] = {1,2,3};
      for(index = 0; index &lt; NUMBER_OF_CUSTOMERS; ++index){
          printf("\nCreating thead %d\n", index);
          result = pthread_create(&amp;threads[index],NULL,request_resources,req);    
  
      }
  
  
  
  
  
     printf("\nDone");
  
  }
  </code></pre>