title: Client Server programming with threads
body: <p>I am working on client server code where a client has two threads running; I want both these threads to run continuously for 60 sec. However, I am facing two problems. </p>
  
  <p>Firstly, when I am running the for loop in <code>main()</code>, the <code>retail_thread()</code> is generating the same number it should have generated random number instead, as <code>bulk_thread()</code> is generating. Secondly, I am not able to get the idea of running the for loop exactly 60 sec.</p>
  
  <p>As it is a homework problem I will really appreciate any hints or assistance if not the exact solution. Please ignore typos if any.</p>
  
  <pre><code>int main(int argc, char *argv[]) {
  
      int pt,i;
      pthread_t thread;
      /* n a very large number */
      /* run below code for 60 seconds */
  
      for(i=0;i&lt;n;i++)
      {
          pt = pthread_create(&amp;thread, NULL, retail_thread, (void*) NULL);
          bulk_thread(NULL);
      }
  }
  
  void* retail_thread(void* ){
      srand(time(NULL));                       
      int order_size = rand()%20 + 1;         
      printf("in retail \n ");
      sendtoserver_R(RETAIL_PORT,order_size);
      int wait_time = 100 + (5*order_size);
      printf("Retail thread order = %d and execution fully completed \n\n",order_size);
  }
  
  void* bulk_thread(void* ){
      srand(time(NULL));                      
      int order_size = rand()%90 + 10;        
      printf("in bulk \n");
      int wait_time = 100 + (5*order_size);
      sendtoserver_B(BULK_PORT,order_size);
  
      printf("Bulk thread order = %d and execution fully completed \n\n",order_size);
  }
  </code></pre>
  
  <p><code>sendtoserver()</code> is just for creating socket and sending data to server.</p>