title: Using a global struct with pthreads in C
body: <p>I'm trying to simulate clients going into a bank and being served by tellers over a period of time.  I am using a thread to determine if a client came into the bank via an arrival rate and am using multiple threads to represent tellers with an s service rate.  I am using a struct to hold the period of time, arrival rate, service rate, number of tellers, and the customer waiting queue.  I am attempting to share that struct between all threads but get "dereferencing pointer" errors and "request for member x in something not a structure" error.  </p>
  
  <pre><code>//Used to store information input by user and the customer queue
  struct shiftInfo {
      int tellers;
      int serviceTime;
      int simTime;
      int sampleInterval;
      int threadID;
      float arrivalRate;
      int Q[]; //Customer Queue
  };
  </code></pre>
  
  <p>The information is passed from into the struct from the command line via </p>
  
  <pre><code>    struct shiftInfo *Q = malloc(sizeof(struct shiftInfo) + (maxCust*sizeof(int)));
      struct shiftInfo info;
      info.simTime = atoi(argv[1]);
      info.arrivalRate = atof(argv[2]);
      info.tellers = atoi(argv[3]);
      info.serviceTime = atoi(argv[4]);
      info.sampleInterval = atoi(argv[5]);
      //Initiates Q to 0
      for (int i = 0; i &lt; maxCust; i++)
          info.Q[i] = 0;
  </code></pre>
  
  <p>The teller, timer, and customer threads are created and terminated by a main thread </p>
  
  <pre><code>  //Manager thread is main thread
    pthread_t manager;
    iret = pthread_create(&amp;manager, NULL, mainThread, (void *)&amp;info);
    if (iret){
      printf("ERROR: return code %d\n", iret);
      exit(-1);
      }
  </code></pre>
  
  <p>To keep this short I'm going to only ask about the timer thread and hopefully apply the answer to the other threads.  The timer thread is created in the main thread by:</p>
  
  <pre><code>  int status;
    struct shiftInfo *I = info; 
    pthread_t time;
        status = pthread_create(&amp;time, NULL, timer, (void *)info);
        if (status){
          printf("ERROR CODE: %d\n", status);
          exit(-1);
      }
  </code></pre>
  
  <p>And the timer thread function is:</p>
  
  <pre><code>void *timer(void *info){
      int timeRemaining = info -&gt; simTime;
      while(timeRemaining){
          sleep(1);
          timeRemaining--;
          }
  }
  </code></pre>
  
  <p>For "int timeRemaining = info -> simTime;" I get the warning "dereferencing void pointer" and the error  request for member âsimTimeâ in something not a structure or union.
  Any advice would be appreciate.</p>
  
  <p>Also, I create the customer thread identically to the way I create the timer thread but receive a warning (warning: passing argument 3 of âpthread_createâ makes pointer from integer without a cast [enabled by default]) that I do not receive when creating any other thread, what causes that?</p>
  
  <pre><code>pthread_t customer;
      status = pthread_create(&amp;customer, NULL, customer, (void *)info);
          if (status){
              printf("ERROR CODE: %d\n", status);
              exit(-1);
          }
  </code></pre>