title: Scheduling pthreads in Round-robin method
body: <p>I am working on a multi-threaded server application.The server accepts connections from multiple devices and assign each connection a thread.The thread is a looping thread i.e it uses a while loop which iterates until the client closes the connection.</p>
  
  <p>Currently when multiple clients got connected to the server only single client is able to communicate i.e the data sent by a single device is received at the server side and updated in database the other devices remain connected to server but no data is received from them. what seems the reason to me (not sure only assuming) is that only a single thread remains executing and other threads don't get the turn to execute. </p>
  
  <p>so I want to schedule threads in round robin so that each thread executes.How can I schedule threads in round robin </p>
  
  <p>I got the following code on-line but it was not able to schedule the threads in round robin.</p>
  
  <pre><code>  pthread_attr_t attr;
    pthread_attr_init(&amp;attr);
    pthread_attr_setscope(&amp;attr, PTHREAD_SCOPE_SYSTEM);
    pthread_attr_setschedpolicy(&amp;attr, SCHED_RR);
  </code></pre>
  
  <p>Here is my code which creates threads:</p>
  
  <pre><code>connfd = accept(sock_desc, (struct sockaddr *)&amp;echoClntAddr,(socklen_t*)&amp;clntSock);
  
   if(connfd &gt; 0){  
       conn_desc = connfd;
       puts("Connection accepted");
  
  if(pthread_create( &amp;thr, &amp;attr ,  connection_handler , (void*)&amp;conn_desc) &lt; 0){    
    perror("could not create thread");
  }
  </code></pre>