title: Do sleep functions sleep all threads or just the one who call it?
body: <p>I am programming with pthread on linux(Centos)? I wanna to threads sleep a short time to wait for something. I am trying to use sleep(), nanosleep(), or usleep() or maybe something can do that. I want to ask that: Do sleep functions sleep all threads or just the one who call it? Any advices or references would be appreciate.</p>
  
  <pre><code>void *start_routine () {
      /* I just call sleep functions here */
      sleep (1); /* sleep all threads or just the one who call it? 
                    what about nanosleep(), usleep(), actually I 
                    want the threads who call sleep function can 
                    sleep with micro-seconds or mili-seconds.  
                 */
      ...
  }
  
  int main (int argc, char **argv) {
      /* I just create threads here */
      pthread_create (... ...);
      ...
      return 0;
  }
  </code></pre>
  
  <hr>
  
  <p>My test program:</p>
  
  <pre><code>#define _GNU_SOURCE
  #include &lt;pthread.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;sched.h&gt;
  #include &lt;unistd.h&gt;
  
  void *start_routine (void *j) {
  
      unsigned long sum;
      int i;
      int jj;
      jj = (int)j;
      do {
          sum = 1;
          for (i=0; i&lt;10000000; i++) {
              sum = sum * (sum+i);
          }
          if (jj == 0) {
              printf ("\033[22;33m[jj%d.%ld]\t", jj, sum);
              sleep(1);           
          }
          else {
              printf ("\033[22;34m[jj%d.%ld]\t", jj, sum);
          }
  
      }while (1);
  
      pthread_exit((void *)0);
  }
  int main(int argc, char *argv[])
  {
      cpu_set_t cpuset;
      pthread_t thread[2];
      int i;
      i = 0;
      CPU_ZERO(&amp;cpuset);
      CPU_SET(i, &amp;cpuset);
  
      pthread_create (&amp;thread[0], NULL, start_routine, (void *)i);
      pthread_setaffinity_np(thread[0], sizeof(cpu_set_t), &amp;cpuset);
      i = 1;
      CPU_ZERO(&amp;cpuset);
      CPU_SET(i, &amp;cpuset);
      pthread_create (&amp;thread[1], NULL, start_routine, (void *)i);
      pthread_setaffinity_np(thread[1], sizeof(cpu_set_t), &amp;cpuset);
      pthread_exit (NULL);
  }
  </code></pre>